Import XML as text on Mac version

jlduerr

New Member
Joined
Sep 3, 2021
Messages
6
Office Version
  1. 365
Platform
  1. MacOS
Hey all,

My team has an Excel report that we generate from a macro that is importing an XML file. However, my team also works on Macs and the macro does not run properly without opening the file in a virtual emulator with Windows. They have been creating reports via this method for years..

Anyways, I've been searching for a better way and noticed the Mac version of Excel does not have the Import XML functionality. I did, however, notice that the Mac version of Excel will treat an XML file as a text file and the data could still be imported accordingly. I've created a brand new macro to attempt this method (code below). This newly created macro runs properly on my Mac and virtual Windows and the others' virtual Windows versions. However, this macro does not run properly on the others' Mac versions. It will come up with an error and the debug highlights the .Refresh BackgroundQuery:=False line.

Does anyone know what might be causing this? It would be great have this working on everyone's Macs.


Code:
Sub ImportText()

Dim FilePath As String
Dim FolderPath As String
FolderPath = ThisWorkbook.Path
FilePath = FolderPath & "/ReportInfo.xml"

Worksheets("Data").Activate
 Range("B1").Select
    Application.CutCopyMode = False
    With Sheets("Data").QueryTables.Add(Connection:= _
        "TEXT;" & FilePath, Destination:=Range( _
        "$B$1"))
        .Name = "PressReportInfo_1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .RefreshPeriod = False
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 10000
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1)
        .TextFileFixedColumnWidths = Array(100)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Range("C1").Select
End Sub
 
Last edited by a moderator:
I wonder if the "ThisWorkbook.Path" command functions differently between Windows versus Mac?
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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