Run-time error '91': Object variable or With block variable not set

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:

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
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
From the computer that works, go to VB Editor, and from the Tools menu, select References. Note all the references that are selected.
Now, repeat the process on the Mac. Are all the necessary references selected? If not, find the missing ones and select them.
Note that there might be slight variations in the version numbers, based on the versions of Office you have. Usually, you just want to pick the most recent one, if there is not an exact match.
 
Upvote 0
To the best of my knowledge, you just can't use FileDialog on a Mac. Check through Ron's site at macexcel.com
 
Upvote 0
From the computer that works, go to VB Editor, and from the Tools menu, select References. Note all the references that are selected.
Now, repeat the process on the Mac. Are all the necessary references selected? If not, find the missing ones and select them.
Note that there might be slight variations in the version numbers, based on the versions of Office you have. Usually, you just want to pick the most recent one, if there is not an exact match.
I checked the references from both computers and they match. Thanks for the advice!
 
Upvote 0
To the best of my knowledge, you just can't use FileDialog on a Mac. Check through Ron's site at macexcel.com
Thanks for your input. I checked out Ron's site and honestly, it may be a little bit over my head. I couldn't really find anything that matched what I am needing.
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top