Access: VBA Code: Apply Format to All Sheets

gisquared

New Member
Joined
Oct 22, 2013
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have been trying to figure this out for several days, hopfully some genius out there can help me. I know I'm close, but just can't get the results I am looking for.

Background:
I have created 5 report in Access: Have successfully exported them to an Excel Workbook:
Now, I am trying to select all 5 sheets and apply these formattings to the sheets AT THE SAME TIME to shorten code:
Insert a row: Apply Filter to new row: Change color of header row:Freeze panes on cell D3: Apply borders to all rows: etc...
there are other things, to "Make it pretty" but once I get started, I'm sure I will get it ok...
Here is the code: I have unactivated a lot of it because I am just trying to get started. I also changed the file names (work IP and all)
The program has a RUN_TIME ERROR '91': Object variable or With block variable not set
I have the following references checked in Tools: References: Visual Basic for Applications: Microsoft Access 14.0 Object Library: OLE Automation: Microsoft Office 14.0 Access database engine Object Library: Microsoft ActiveX Data Objects 6.1 Library: Microsoft ADO Ext. 6.0 for DDL and Sedurity: Microsoft Excel 14.0 Object Library: Microsoft Office 14.0 Object Library: Microsoft Scripting Runtime:

I found the code Dim sh as workshet at:
http://www.mrexcel.com/forum/excel-...pplications-code-apply-format-all-sheets.html

Hopefully I provided enough information.... I know there has to be a way to Export and Format as a single sheet (have done this many times) I just am looking to keep a short code and apply all formatting at one time.

Thanks in advance for any/all help.

Private Sub Export_In_Order_Click()
DoCmd.SetWarnings False

DoCmd.TransferSpreadsheet acExport, 10, _
"A_Dn_Fin", "C:\MASTER LOG mm-dd-yyyy WWxx'13.xlsx"

DoCmd.TransferSpreadsheet acExport, 10, _
"B_PF_Fin", "C:\MASTER LOG mm-dd-yyyy WWxx'13.xlsx", True

DoCmd.TransferSpreadsheet acExport, 10, _
"C_S_Fin", "C:\MASTER LOG mm-dd-yyyy WWxx'13.xlsx", True
DoCmd.TransferSpreadsheet acExport, 10, _
"D_Con1_Fin", "C:\MASTER LOG mm-dd-yyyy WWxx'13.xlsx", True
DoCmd.TransferSpreadsheet acExport, 10, _
"E_Con2_Fin", "C:\MASTER LOG mm-dd-yyyy WWxx'13.xlsx", True

'Sub Applyformats()
Dim sh As Worksheet
'For Each sh In ActiveWorkbook.Sheets
For Each sh In ActiveWorkbook.Sheets
sh.Activate
Columns("A:AF").EntireColumn.AutoFit
'Range("D3").Activate
'ActiveWindow.FreezePanes = True
Next sh
'End Sub

'Format
'oApp.Range("A1").Select

'oApp.ActiveCell.Offset(1).EntireRow.Insert
'oApp.Range("A1:AF20000").Font.Name = "Arial"
'oApp.Range("A1:AF20000").Font.Size = 8
'oApp.Range("A1:AF1").Interior.Color = RGB(141, 180, 226)
'oApp.Range("A2:AF2").Interior.Color = RGB(255, 255, 153)
'oApp.Range("A1:AF1").Font.Bold = True
'oApp.Range("A2:AF2").AutoFilter
'oApp.Range("AF1").Select

'oApp.Range("3:3").Select
'oApp.ActiveWindow.FreezePanes = True
'oApp.Columns("A:AF").EntireColumn.AutoFit

'oApp.Range("A1:AF20000").HorizontalAlignment = xlCenter
'oApp.Range("A1:AF1").Borders(xlEdgeBottom).LineStyle = xlContinuous
'oApp.Range("A1:AF1").Borders(xlEdgeBottom).Weight = xlThin
'oApp.Range("A1:AF1").Borders(xlEdgeLeft).LineStyle = xlContinuous
'oApp.Range("A1:AF1").Borders(xlEdgeLeft).Weight = xlThin
'oApp.Range("A1:AF1").Borders(xlEdgeRight).LineStyle = xlContinuous
'oApp.Range("A1:AF1").Borders(xlEdgeRight).Weight = xlThin
'oApp.Range("A1:AF1").Borders(xlEdgeTop).LineStyle = xlContinuous
'oApp.Range("A1:AF1").Borders(xlEdgeTop).Weight = xlThin
'oApp.Range("A1:AF1").Borders(xlInsideVertical).LineStyle = xlContinuous
'oApp.Range("A1:AF1").Borders(xlInsideVertical).Weight = xlThin
'oApp.Range("A1:AF1").Borders(xlInsideHorizontal).LineStyle = xlContinuous
'oApp.Range("A1:AF1").Borders(xlInsideHorizontal).Weight = xlThin

'oApp.Sheets("Des").Select

'oApp.Range("A1").Select

'oApp.DisplayAlerts = False

DoCmd.SetWarnings False

MsgBox "Export L to R Complete"
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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