dsheard2015
Board Regular
- Joined
- May 10, 2016
- Messages
- 134
Hello,
I have created a worksheet on my windows pc with vba to select a file from the computer. The code runs when I select a button. When I try to use this same worksheet on my Mac and click the button to run the code, I get an error, "Run-time error '91': Object variable or With block variable not set. Help, Continue, End, Debug.
This worksheet and code has always worked from my windows pc and I only get the error when working from a Mac. Any help in correcting this error is greatly appreciated! When I select "Debug" on the error message, the line .Title = "Select Word file to attach" is highlighted. The code is below:
I have created a worksheet on my windows pc with vba to select a file from the computer. The code runs when I select a button. When I try to use this same worksheet on my Mac and click the button to run the code, I get an error, "Run-time error '91': Object variable or With block variable not set. Help, Continue, End, Debug.
This worksheet and code has always worked from my windows pc and I only get the error when working from a Mac. Any help in correcting this error is greatly appreciated! When I select "Debug" on the error message, the line .Title = "Select Word file to attach" is highlighted. The code is below:
VBA Code:
Option Explicit
Sub AddWordTemplate()
Dim WordTempLoc As FileDialog
Dim FirstRow As Long
Set WordTempLoc = Application.FileDialog(msoFileDialogFilePicker)
FirstRow = Sheet2.Range("E101").End(xlUp).Row + 1 'First Available Row
With WordTempLoc
.Title = "Select Word file to attach"
.Filters.Add "Word Type Files", "*.docx,*.doc", 1
If .Show <> -1 Then GoTo NoSelection
Sheet2.Range("E" & FirstRow).Value = Dir(.SelectedItems(1)) 'Document Name
Sheet2.Range("F" & FirstRow).Value = .SelectedItems(1) 'Document Pathway
End With
NoSelection:
End Sub