473,652 Members | 2,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to format multiple sheets in Excel?

anoble1
245 New Member
Hello - I have made something that opens an excel document that was just exported. The workbook has 10 tabs. I wish there was someway to edit all the tabs instead of doing it tab by tab in the code. Is there a way to do that? Right now I am only able to do "Sheet1" of course.

Expand|Select|Wrap|Line Numbers
  1. Private Sub OpenAndFormatExcel()
  2.  
  3.     Dim filePath As String
  4.  
  5.     filePath = "C:\Users\Andy\Documents\Andy\Test.xlsx"
  6.  
  7.     Dim XL As Excel.Application
  8.     Dim xlBook As Excel.Workbook
  9.     Dim xlSheet As Excel.Worksheet
  10.  
  11.     Set XL = New Excel.Application
  12.  
  13.     Set xlBook = XL.Workbooks.Open(filePath)
  14.  
  15.     Set xlSheet = xlBook.Worksheets("Sheet1")
  16.  
  17.     XL.Visible = True
  18.     FreezeRow
  19.  
  20.     With xlSheet
  21.  
  22.         With .Range("A1:L1")
  23.             .HorizontalAlignment = Excel.xlCenter
  24.             .Font.Bold = True
  25.             .Columns.AutoFit
  26.             .EntireColumn.AutoFit
  27.         End With
  28.  
  29.     End With
  30.  
  31.     XL.DisplayAlerts = False
  32.  
  33.     xlBook.Save
  34.     '*** uncomment to keep open
  35.     'xlBook.Close True
  36.  
  37.     XL.DisplayAlerts = True
  38.  
  39.     Set xlSheet = Nothing
  40.     Set xlBook = Nothing
  41.     Set XL = Nothing
  42.  
  43. End Sub
  44.  
  45. Sub FreezeRow()
  46. Rows("2:2").Select
  47. ActiveWindow.FreezePanes = True
  48. End Sub
  49.  
Feb 1 '23 #1
6 8276
NeoPa
32,568 Recognized Expert Moderator MVP
Have you tried recording doing what you want in Excel first? You can Select multiple Worksheets in Excel, as you may know, so then you add your formatting. When you stop recording the macro you have some example code that is usually very poor code, TBF, but nevertheless gives you hints at the steps you will need in your proper code. Does that make sense?

Separately, when converting from Excel code into something that works from within Access you need to ensure any defaults that are used by Excel are specified explicitly when running from Access. Check out Application Automation.
Feb 1 '23 #2
tmudgal16
10 New Member
I want to format all the worksheets like Sheet1. Here's what I'll do:

1) Group the worksheets by selecting Sheet1, holding down the Shift key and selecting Sheet4. This will group all the worksheets together:
Notice in the header it now says "Group":

2) Go to Home > Editing > Fill > Across Worksheets…
3) A dialog box will pop up. Select "Formats" and click OK:
Feb 6 '23 #3
NeoPa
32,568 Recognized Expert Moderator MVP
While that last post doesn't deal with the question directly, as it isn't code-related at all, it is valid as it does give an example of how to duplicate formatting across Worksheets that can be captured by the macro recorder.

It's not exactly the approach I had in mind as applying specific format commands to a selection of Worksheets makes more sense to me and I suspect it would be easier to control exactly which formats are included across the selected Worksheets.
Feb 6 '23 #4
SioSio
272 Contributor
At the beginning of your code, insert the code to select all sheets.
Expand|Select|Wrap|Line Numbers
  1.     Dim selSht As Variant
  2.     Dim i As Long
  3.     ReDim selSht(1 To Sheets.Count)
  4.     For i = 1 To Sheets.Count
  5.         selSht(i) = Sheets(i).Name
  6.     Next i
  7.     Sheets(selSht).Select
Feb 7 '23 #5
Varsha1285
16 New Member
1.Ctrl + Click each sheet tab at the bottom of your worksheet (selected sheets will turn white).

2. While selected, any formatting changes you make will happen in all of the selected sheets.

3. Double-click each tab when you are done to un-select them.
Feb 8 '23 #6
NeoPa
32,568 Recognized Expert Moderator MVP
Hi Varsha.

I won't delete your post as I assume it was intended to help - and there may be some that read it later who find it helpful.

However, it really is necessary to read the question before posting an answer. The question was clear about wanting to edit multiple tabs (Worksheets) using code (VBA).

No matter how good the intention, it's frustrating to ask questions and see an answer - only to find it has nothing really to do with your question (Like this response to you now, unfortunately).

@ANoble.
Perhaps you could update the thread with where you are with it now. Hopefully my post #2 led you to what you needed.
Feb 8 '23 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
21512
by: Carl Corcoran | last post by:
I'm developing a website for work that exports some reports to excel. I am using the... Response.AddHeader "Content-Disposition","attachment;filename=report.xls" Response.ContentType = "application/vnd.ms-excel" ....strategy to do this. It works wonderfully except I cannot figure out how to do two things: 1) specify a name for the worksheet that's exported (it names the
0
3469
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined one which creates a pivot table and sorts it into different fromats. Here is the code, can any body help? Sub Update_Land_Actuals() On Error Resume Next If InputBox("Enter password to continue", "Centex Homes") <> "***" Then Exit Sub...
4
7350
by: Harshe | last post by:
hello all, I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with. In a workbook at the start of the year (january) i will have 4 sheets and these sheets will keep increasing to 12 when the month is december. so i want is, sheet 1 (named abc) should go into table 1 (named abc), sheet 2 (named def)should go into table 2 (named def), sheet 3 (named xyz) should go into table 3 (named...
1
6187
by: CF FAN | last post by:
Can Report Builder Export Excel Files with multiple Sheets How can I create a report that it can export in excel by multiple
0
1305
by: Supermansteel | last post by:
I have created an Form and Input sheet to be able to input Pricing informtion for 1st and 2nd Mortgages. However, I have recently come accross that there are about 13 states that have different pricing for 1st and 2nd Mortgages because of state guidelines. I takes me about 15 minutes to input the information from an the Pricing sheet into my Form. They have sent me an excel file with about 28 different Tabs for the different Pricing for each...
0
1886
by: puneetmittal33 | last post by:
Hi, I am facing the following issues and hoping that someone out there would have a resolution to the issue: 1) I am currently working on a web application which handles the payroll data for 40000+ employees. 2) The application needs to spool web based reports in Excel sourcing the data from the backend using regular queries. 3) I am currently stuck at the part when I need to generate an Excel file with multiple sheets and formatting...
7
8067
by: elham a | last post by:
I have an Excel workbook with multiple sheets (22)! that I would like to import into Access Tables for manipulation. I'd like to load them all to the same table if possible, so long as I know what the name of the sheet the records came from originally. Is there any systematic way of doing this?
1
884
by: anourmohammadi | last post by:
hi is there any way ? "Exporting Tables from Access into 1 Excel Workbook w/ Multiple Sheets" with no code .
0
1637
by: vinodpaladi | last post by:
how to export the reports data from ms access to excel in multiple sheets
8
4082
USTRAGNU1
by: USTRAGNU1 | last post by:
Good Day, I created a macro in Excel that works great. It formats multiple sheets exactly as expected, but when it completes it seems like I have to close out four or five worksheets before I can close out of excel completely. One item of note: I experienced errors when I first built the macro. When I went in to edit the macro, I noticed a ton of temp macros that were never there before. Could I assume this is the problem? Has anyone heard...
0
8811
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.