I have transfer spreadsheet code that creates an Excel workbook with 4 tabs (Tab1, Tab2, Tab3, Tab4). i then want to format the worksheets where the first row of each is bold and all columns are autofit, however Tab1 should have columns C and beyond be formatted with two decimal places, and Tab3 should have columns C and beyond be formatted as currency (if this doesn't work, two decimal places will be acceptable).
Tab1 comes out perfectly. The cells have two decimal places and everything is formatted wonderfully. Tab2, Tab3, and Tab4 are all formatted as far as the first row being bold, but the columns are not Autofit and Tab3 does not have the decimal place formatting. I've tried both .NumberFormat = "0.00" and .NumberFormat = "$0.00". When I use the latter, Tab1 is formatted with the $ sign instead of Tab3. I even went so far as swapping the order in the code between Tab1 and Tab3, but Tab1 is still correctly formatted and Tab3 still has too many decimal places and no dollar sign.
Also, when it gets to each .Save point, it states that RESUME.XLW already exists and asks if the user would like to overwrite it (if the code has been previously run). Is there a way to make this save automatically so the user doesn't have to click Yes?
Thanks!
Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Tab1", "[URL="file://\\nmchqt59\nmc"]Path[/URL]"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Tab2", "[URL="file://\\nmchqt59\nmc"]Path[/URL]"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Tab3", "[URL="file://\\nmchqt59\nmc"]Path[/URL]"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Tab4", "[URL="file://\\nmchqt59\nmc"]Path[/URL]"
strWkbkName = "[URL="file://\\nmchqt59\nmc"]Path[/URL]ls"
strWkSt = "Tab1"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Rows("5:99").NumberFormat = "0.00"
.Save
.Workbooks.Close
End With
strWkSt = "Tab2"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Save
.Workbooks.Close
End With
strWkSt = "Tab3"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Save
.Workbooks.Close
End With
strWkSt = "Tab4"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Rows("2:99").NumberFormat = "0.00"
.Save
.Workbooks.Close
End With
Tab1 comes out perfectly. The cells have two decimal places and everything is formatted wonderfully. Tab2, Tab3, and Tab4 are all formatted as far as the first row being bold, but the columns are not Autofit and Tab3 does not have the decimal place formatting. I've tried both .NumberFormat = "0.00" and .NumberFormat = "$0.00". When I use the latter, Tab1 is formatted with the $ sign instead of Tab3. I even went so far as swapping the order in the code between Tab1 and Tab3, but Tab1 is still correctly formatted and Tab3 still has too many decimal places and no dollar sign.
Also, when it gets to each .Save point, it states that RESUME.XLW already exists and asks if the user would like to overwrite it (if the code has been previously run). Is there a way to make this save automatically so the user doesn't have to click Yes?
Thanks!