Note that there are some explanatory texts on larger screens.

plurals
  1. POTransfering windows-specific macro to run on Mac Excel
    primarykey
    data
    text
    <p>I've recently changed from a PC to a Mac. I run a lot of a macros and 99% of them are running fine, but I have one that doesn't work on a Mac.</p> <p>It runs a set of other macros across all workbooks in a file. To do this it uses strings like this:</p> <p><code>Function BrowseFolder(Title As String, _ Optional InitialFolder As String = vbNullString, _ Optional InitialView As Office.MsoFileDialogView = _ msoFileDialogViewList) As String</code></p> <p>When I try to run this on the Mac it comes back with an error: </p> <blockquote> <p>"compile error: variable not defined"</p> </blockquote> <p>I wonder if anyone could help me with porting this macro over to run on Mac. It was built on Excel 2007 Windows and I'm trying to run it on Excel 2011 Mac.</p> <pre><code>Option Explicit Function GetFolder(Optional strPath As String) As String Dim fldr As FileDialog Dim sItem As String Set fldr = Application.FileDialog(msoFileDialogFolderPicker) With fldr .Title = "Select a Folder" .AllowMultiSelect = False If Not IsEmpty(strPath) Then .InitialFileName = strPath End If If .Show &lt;&gt; -1 Then GoTo NextCode sItem = .SelectedItems(1) End With NextCode: GetFolder = sItem Set fldr = Nothing End Function Private Sub test() Dim v As Variant 'V = GetFolder() v = BrowseFolder("Select folder") End Sub Function BrowseFolder(Title As String, _ Optional InitialFolder As String = vbNullString, _ Optional InitialView As Office.MsoFileDialogView = _ msoFileDialogViewList) As String Dim v As Variant Dim InitFolder As String With Application.FileDialog(msoFileDialogFolderPicker) .Title = Title .InitialView = InitialView If Len(InitialFolder) &gt; 0 Then If Dir(InitialFolder, vbDirectory) &lt;&gt; vbNullString Then InitFolder = InitialFolder If Right(InitFolder, 1) &lt;&gt; "\" Then InitFolder = InitFolder &amp; "\" End If .InitialFileName = InitFolder End If End If .Show On Error Resume Next Err.Clear v = .SelectedItems(1) If Err.Number &lt;&gt; 0 Then v = vbNullString End If End With BrowseFolder = CStr(v) End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload