1
私は同僚のマシンにいくつかのコードをインストールしようとしたときにいくつかのコードに問題があります。 Outlookのマシンとバージョンはまったく同じで、同じライブラリを参照します。しかし、自分のマシンでスクリプトを実行しようとすると、Set xlWB = xlApp.Workbooks.Open(strPath)にエラー91がスローされます。エラーコード91が別のマシンにインストールしようとしています
指定された電子メールメッセージから、指定されたディレクトリにあるExcelスプレッドシートに必要なデータをエクスポートすることを意図しています。
エラーを取り除くために何を試すべきかの手掛かりはありますか?下のコードの前半。
多くの感謝!
Option Explicit
Sub ServiceRequestTool()
Dim xlApp As Object
Dim xlWB As Object
Dim xlSheet As Object
Dim rCount As Long
Dim bXStarted As Boolean
Dim enviro As String
Dim strPath As String
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim olItem As Outlook.MailItem
Dim obj As Object
Dim strColA, strColB, strColC As String
strPath = "H:\My Documents\General Docs\Govtnz-Service-Request.xlsm"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
If Dir$("H:\My Documents\General Docs\Govtnz-Service-Request.xlsm") = "" Then
MsgBox "Contact the spreadsheet administrator for assistance.", vbOKOnly + vbCritical, "File not found!"
Exit Sub
End If
End If
On Error GoTo 0
Set xlWB = xlApp.Workbooks.Open(strPath)
Set xlSheet = xlWB.Sheets("requestAssignment")
On Error Resume Next
rCount = xlSheet.Range("C" & xlSheet.Rows.Count).End(-4162).Row + 1
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each obj In Selection
Set olItem = obj
strColA = olItem.SenderName
strColB = olItem.SenderEmailAddress
strColC = olItem.ReceivedTime
xlSheet.Range("B" & rCount) = strColC
xlSheet.Range("C" & rCount) = strColA
xlSheet.Range("D" & rCount) = strColB
rCount = rCount + 1
Next
xlWB.Close 1
If bXStarted Then
xlApp.Quit
End If
Set olItem = Nothing
Set obj = Nothing
Set currentExplorer = Nothing
Set xlApp = Nothing
Set xlWB = Nothing
Set xlSheet = Nothing
End Sub
の可能性のある重複した[VBA:?実行時エラー '91'](http://stackoverflow.com/questions/18927297/vba-run-time-error-91) – Marged
ハードコーディングされたファイルパスは他のマシンからアクセスできますか? – Comintern
あなたの同僚のマシンの 'H'ドライブはあなたと同じ 'H'ドライブですか?代わりにUNC名を使用してください(例:\\ MyServerName \ MyFolder \)。 'GetObject'もチェックしてください - Siddarthは彼の答えでそれを説明しています。編集 - あなたが 'Dir'と一緒に存在することを確認します。 –