Forum Discussion
Freeze Panes issue with Power Query
- Anonymous6 years ago
It would be rather easy to write a VBA macro (or even a script in PowerShell or Python) that would go through all Excel files in a folder, silently open them without even showing the file on the screen, change the setting on every sheet and then save them. No manual work required and very quick. Excel is an automation OLE server, so you can automate it from almost anything... All you need is to import the Excel object library which can be found on every computer with Excel.
Best
D
hi I see same issue as of 7/2023. what is plan to fix, what is workaround?
- DannyMcMate3 years agoFrequent Visitor
Hi, the workaround I went with was to set up a macro that I could point at a folder containing my reports which would format the data in them as an Excel Table which I could then retrieve with PowerQuery.
This is the Sub I use:Sub Select_Reports_Folder()
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String'Macro optimisation settings
Application.Calculation = xlManual
Application.ScreenUpdating = False'Retrieve reports folder path
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Reports Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo ResetSettings
myPath = .SelectedItems(1)
End With'Target file extension (must include wildcard "*")
myExtension = "*.xls*"'Target path with ending extention
myFile = Dir(myPath & "\" & myExtension)'Loop through each Excel file in folder
Do While myFile <> ""'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=myPath & "\" & myFile)
'Formatting changes
wb.Sheets(1).Select
If Range("A1").CurrentRegion.ListObject Is Nothing Then
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1").CurrentRegion, , xlYes).Name = "Table1"
wb.Close SaveChanges:=True
Else
wb.Close SaveChanges:=False
End If
'Get next file name
myFile = Dir
Loop'Message box when tasks are completed
MsgBox "Task Complete"'Reset macro optimisation settings
ResetSettings:
Application.Calculation = xlAutomatic
Application.ScreenUpdating = TrueEnd Sub