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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,910
Office Version
  1. 365
Platform
  1. Windows
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,693
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
To the best of my knowledge, you just can't use FileDialog on a Mac. Check through Ron's site at macexcel.com
 

dsheard2015

Board Regular
Joined
May 10, 2016
Messages
134
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!
 

dsheard2015

Board Regular
Joined
May 10, 2016
Messages
134
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,297
Messages
5,635,380
Members
416,856
Latest member
silentir

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
Top