2013-10-17 58 views

回答

1

是的,這是可能的。

下面是一個例子:

Sub RunExcelMacro() 
Dim xl As Object 
'Step 1: Start Excel, then open the target workbook. 
    Set xl = CreateObject("Excel.Application") 
    xl.Workbooks.Open ("C:\Book1.xlsm") 

'Step 2: Make Excel visible 
    xl.Visible = True 

'Step 3: Run the target macro 
    xl.Run "MyMacro" 

'Step 4: Close and save the workbook, then quit the Excel application 
    xl.ActiveWorkbook.Close (True) 
    xl.Quit 

'Step 5: Memory Clean up. 
    Set xl = Nothing 

End Sub 
+0

謝謝!這很好!現在唯一的問題是,我開始關閉它,因爲我的老闆想要儘可能多的自動化。當我運行你給我的代碼時,它會在宏執行後立即關閉wb。請指教。 – autumntiger