I am trying to write a module that will open excel, print the file and close the program by just pressing a button on switchboard manager, however i am having a really hard time getting started.
can someone please give me some ideas and pointers
Perhaps something like this might be helpful:
(Be sure to reference MS Excel 10.0 Object Library in tools-references)
Private Sub PassVariable()
On Error GoTo Err_Routine
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Set objXL = New Excel.Application
Set objWkb = objXL.Workbooks.Open("C:\Documents and Settings\YourFileName.xls")
Set objSht = objWkb.Worksheets("SheetName")
objSht.PrintPreview
DoEvents
objWkb.Save
objXL.Quit
Set objSht = Nothing
Set objWkb = Nothing
Set objSht = Nothing
Exit Sub
Err_Routine:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub
In order for a VBA macro to work, Don't you have to have that Excel file open? It sounds like you need a simple VB program that is aside from Excel. Have you tried to "Record a New Macro"? When you record a new macro you do the events you wish for the Macro to do for you. Tryit and see if it works...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.