Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference open Excel from Word in different Subs? 1

Status
Not open for further replies.

gtaborda

Programmer
May 13, 2007
75
GB
Hi

I have used the code from Vroscioli in thread 840925 to open excel from word.
Works fine.

However i am now trying to continue adding data from another Routine (cmbbox_afterupdate) and there seems there is no reference (I get a "424 Needs an Object" error)

How can I give the Excel Objects a global reference so I can use it on any other routines within the module?

This is how I opened the Excel...

Public Sub OpenExcel()

Dim xl as Excel.Application
Dim wb as Excel.Workbook
Dim sh as Excel.Worksheet

Set xl = CreateObject("Excel.Application")
xl.Visible = true
Set wb = xl.Workbooks.Open("filename")
Set sh = wb.Worksheets("worksheetname")

txtYourTextBox = sh.[a1]

'wb.Close
'xl.Quit
end sub

Thanks in advance

 
Define the objects outside the procedure body:

Dim xl as Excel.Application
Dim wb as Excel.Workbook
Dim sh as Excel.Worksheet

Public Sub OpenExcel()
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
aaaaaaaaaaaahhhhhhhhhhhh!

How stupid !

Thank you so much !!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top