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

Open Excel file, Run Macro, Save File, Close File

Status
Not open for further replies.

Kendall66

Programmer
Mar 20, 2002
2
US
I need sample code relating to Opening an Excel File, Running a Macro within the file(workbook, then saving the file, then closing the file down. All with one click of the button.

The File will be on a local drive. The Macro will be a basic print macro.


Does anybody have example code relating to this? Would be very helpfull.


Thankyou
 
Hi,
Here is a sample...
Code:
Sub DoItAll()
    Workbooks.Open "H:\PROJECT\BOM_UploadProcessing\vbatemplates.xls"
    With ActiveWorkbook
        .ActiveSheet.PrintOut
        .Save
        .Close
    End With
End Sub
Skip,
metzgsk@voughtaircraft.com
 
If you add the following sub, your code will be executed automatically when you open the excel file:
Sub Auto_Open()
ActiveWorkbook.Worksheets("Sheet1").PrintOut
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top