Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Opening a spreadsheet using VB


Private Sub cmfRefresh_Click()

Dim xlAPP As Object
Dim xlWB As Object

Set xlAPP = CreateObject("Excel.Application")

Set xlWB = _
xlAPP.workbooks.open("H:\May_Timesheet.xls")

xlWB.activesheet.calculate

xlWB.Close True

Set xlWB = Nothing

xlAPP.quit

Set xlAPP = Nothing

End Sub

Instead of using the createobject method, you could set a
reference to the VB6 object library inj the VB IDE.
Then dim xlApp as Excel.Application and then SET xlAp =
New Excel.Application
dim xlWB as Excel.Workbook

the code above uses "late binding" ie you dim an object
but the code doesn't know what it is until the programme
creates the object.
Setting a reference allows "early binding" as I
described, which is, apart from being better and nmore
efficient in regards to compiling the code, enables the
programmer to use intellisense when writing the code.

HTH
Patrick Molloy
Microsoft Excel MVP

Option Explicit
' prog ref to Excel 10 Object Library
Private Sub cmfRefresh_Click()

Dim xlAPP As Excel.Application
Dim xlWB As Excel.Workbook

Set xlAPP = New Excel.Application

Set xlWB = xlAPP.workbooks.open
("H:\May_Timesheet.xls")

xlWB.ActiveSheet.calculate


xlWB.Close True

Set xlWB = Nothing

xlAPP.quit

Set xlAPP = Nothing


End Sub




-----Original Message-----
Hello,
I have a spreadsheet (XP) with links to query's in

Access
XP and SQL 2000 that needs to be opened and refreshed
(Refresh All button is the one that works when done
manually) on all tabs. Would anyone be able to provide
some sample code in VB 6 that would show how to open and
refresh a spreadsheet, then save and close? The first 2
are more important though.

thanks,
Zac
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening Excel spreadsheet OrcaFire Excel Discussion (Misc queries) 0 March 7th 10 07:26 PM
#REF! after opening a spreadsheet AG Excel Discussion (Misc queries) 0 April 27th 07 08:20 PM
opening a spreadsheet stumped New Users to Excel 2 June 10th 06 02:02 AM
Opening a spreadsheet Multiple speadsheets Excel Discussion (Misc queries) 1 March 8th 06 05:15 PM
Opening a spreadsheet using VB Tom Ogilvy Excel Programming 1 August 20th 03 02:25 PM


All times are GMT +1. The time now is 01:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"