I have some VBS code that I use to apply Excel formatting to a spreadsheet:
Set xlObj = CreateObject("Excel.Application")
Set xlFile = xlObj.WorkBooks.Open("C:\Documents and Settings\user\forms.xlsx")
xlObj.Application.DisplayAlerts = False
For Each Worksheet In xlFile.Worksheets
dPriorWorkday = xlObj.Application.WorksheetFunction.WorkDay(Now, -1)
Worksheet.Name = "Forms received " & Year(dPriorWorkday) & "-" & Right("0" & Month(dPriorWorkday),2) & "-" & Right("0" & Day(dPriorWorkday),2)
With Worksheet.Cells.Font
.Name = "Arial"
.Size = 8
End With
Next
xlFile.Close True
xlObj.Quit
I use a .bat file to run this VBS on a .xlsx worksheet, with all 3 files being in the same directory.
What I am trying to do is change the VBS to apply the formatting to a .xlsx file that is in the same directory as the .bat and the .vbs file, so I can remove the direct file path "C:\Documents and Settings\user\"
I have tried:
Workbooks.Open Filename:=ThisWorkbook.Path & "\forms.xlsx"
but it does not work, I assume because that is for .vbs called from the workbook itself.
is there something similar I can use to apply the .vbs to the file in the same directory as the .vbs, without using the full file path?