我遇到一些令人头疼的问题,请拨打个人.xlsm中包含的Excel宏,请帮助我。
我正在运行Outlook 2016.尝试在打开Outlook时从personal.xlsm调用宏。关键问题(我认为基于其他解决方案)是不包括正确的Excel数据对象库,但我已经包含了相关的(没有成功)。
程序只是在没有调用宏的情况下运行 - 我已经在Excel宏的开头放置了一个MsgBox提示,以检查它是否开始运行&每次都失败。
从以下代码中提取;我删除了与此问题无关的代码。
在展望中:ThisSession
Private Sub Application_Startup()
Dim macroFile As String, networkFilePath As String, sourceFile as String
Dim DestFile As String: DestFile = "FolderTree.csv"
Dim SourceFolder As String: SourceFolder = "[NetworkLocation]"
Dim foldersRequired As String
Dim objShell As Object
Dim objFile As Object
Dim fso As FileSystemObject: Set fso = CreateObject("Scripting.FileSystemObject")
Dim xlApp As Object: Set xlApp = CreateObject("Excel.Application") 'open the excel csv source file
Dim xlWkb As Object, xlSht As Object
On Error Resume Next
''get the core xlsb macros file - saves updating the individual user outlook
macroFile = userProfilePath & "\Personal.xlsb"
'This works fine & opens the file with no issues.
Set xlWkb = xlApp.Workbooks.Open(macroFile)
Set xlSht = xlWkb.Worksheets(1)
xlApp.Application.Visible = True
'' extract the users profile path
Set objShell = CreateObject("WScript.Shell")
userProfilePath = objShell.ExpandEnvironmentStrings("%UserProfile%") & "[DataFolder]"
sourceFile = userProfilePath & "\" & DestFile
xlApp.Workbooks("Personal.xlsb").Activate
xlApp.Workbooks.Open FileName:=(sourceFile)
'' This opens fine
If Not xlxApp Is Nothing Then
'' None of the below work
xlWkb.Application.Run "Module1.Clean_CSV(sourceFile, userProfilePath)"
'' This doesn't work
xlWkb.Application.Run "Personal.xlsb!Module1.Clean_CSV(sourceFile, userProfilePath)"
'' This doesn't work
xlWkb.Application.Run "Personal.xlsb!Clean_CSV(sourceFile, userProfilePath)"
'' This doesn't work
End If
xlApp.Close
xlApp.Quit
'' I set all Variables & Objects to Nothing & then
End Sub