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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How would I change this code to open existing Excel instead of new

Status
Not open for further replies.

Cydog

Technical User
Mar 20, 2009
3
US
How would I change this code to open an existing Excel spreadsheet instead of new spreadsheet.

I struggle terribly trying to understand VB code , or any code. What would be the easiest way to modify,this code
below, to open an existing Excel spreadsheet instead
of a new spreadsheet.

Your help is greatly appreciated,

Private Sub Form_Load()

'Start Excel and open new spreadsheet
Set exlApp = New Excel.Application
exlApp.Workbooks.Add
Set exlWSheet = exlApp.Workbooks(1).Worksheets(1)
exlApp.Visible = True
exlRow = 1
exlCol = 1
 
Have a look at
Code:
exlApp.Workbooks.Open()
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks for the reply HarleyQuinn. I will try a few
things with your example. What section of this code would you insert your example. exlApp.Workbooks.Open()

'Start Excel and open new spreadsheet
Set exlApp = New Excel.Application
exlApp.Workbooks.Add
Set exlWSheet = exlApp.Workbooks(1).Worksheets(1)
exlApp.Visible = True
exlRow = 1
exlCol = 1

I took notice that Piowtrpolo started a thread back
in May 2008 for the same Cognex camera VB code I
am working with Thread 222-1475738. If Piowtrpolo is online could you reply with the modifications that you made.

Thanks for your help. Have a great weekend.
 
The thread you referenced has two examples of how to use the workbooks.Open() method, posted by both Swi and Golom, but I'll re-post how to do it
Code:
Dim exlApp As New Excel.Application
Dim exlBook As New Excel.Workbook
Set exlBook = exlApp.Workbooks.Open("C:\Test.xls")
exlApp.Visible = True
' do what you need then dispose...
exlBook.Close
Set exlBook = Nothing
exlApp.Quit
Set exlApp = Nothing
Remember to dispose of the application and workbook instances properly or you'll end up with multiple excel processes running and that can cause some problems.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Remember to dispose of the application and workbook instances properly or you'll end up with multiple excel processes running and that can cause some problems.

Amen!!
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top