简体   繁体   English

打开Excel文件并执行宏

[英]Open Excel file and excute macros

I want to open an Excel file and run the macros ActionImporter and ActionExporter from VBScript. 我想打开一个Excel文件并从VBScript运行宏ActionImporterActionExporter

Here is my code: 这是我的代码:

Option Explicit
On Error Resume Next

Dim AppExcel
Dim repertoireMISAJOURComplete
Dim nomDuFichier

repertoireMISAJOURComplete = "G:\Pole recrutement et mobilite\Testoutil\Serveur_V2.1.1.xlsm"     

nomDuFichier = "Serveur_V2.1.1.xlsm"
Workbooks.Open Filename:= repertoireMISAJOURComplete

Set AppExcel = WScript.CreateObject("Excel.Application")
AppExcel.Visible = True
'On Error Resume Next
'ouvre le classeur
AppExcel.Workbooks.Open (repertoireMISAJOURComplete)
'peut exécuter une macro
'à l'ouverture (ôter l'apostrophe)
'devant AppExcel.Run "Test"
'et changer le nom de la macro :
Windows(nomDuFichier).Activate

Sheets("Administration Serveur").Select
Application.Run nomDuFichier & "!'ActionImporter'"

Windows(nomDuFichier).Activate

Sheets("Administration Serveur").Select
Application.Run nomDuFichier & "!'ActionExporter'"
Set AppExcel = Nothing

'quitte VBS
WScript.Quit

I find the solution so i share with you : 我找到了解决方案,所以我与您分享:

Option Explicit
Dim args, objExcel
Set args = WScript.Arguments
Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Open "G:\Testoutil\Serveur_V2.1.1.xlsm",,,,"myPassword"
objExcel.Visible = True

objExcel.Run "ActionImporter"

objExcel.Run "ActionExporter"

objExcel.Quit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM