[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Formatting Column Widths in Excel Workbook after exporting it from Access

Posted on 2011-03-08
6
Medium Priority
?
574 Views
Last Modified: 2012-05-11
I have an Access 2003 application that creates an Excel Workbook containing about 12 worksheets.  After the workbook gets created I have to go into it and format the column widths on each worksheet.  Is there a way to do this formatting using vba code?
0
Comment
Question by:dsoderstrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35074175
here is  a sample code to do formatting
Private Sub FormatSheet(objXLSheet As Object)
With objXLSheet
        .Range("D2", .Range("D2").End(xlToRight).End(xlDown)).NumberFormat = "#,###.00"
        .Range("C2", .Range("C2").End(xlDown)).NumberFormat = "0.00%"
        .Range("A1", .Range("A1").End(xlToRight).End(xlDown)).Columns.AutoFit
        .Range("A1", .Range("A1").End(xlToRight)).Font.Bold = True
        .Range("A1", .Range("A1").End(xlToRight)).HorizontalAlignment = xlCenter
        .Range("A1").CurrentRegion.Select
End With
End Sub

Open in new window

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35074185
post the codes that you are using to create the excel file
0
 

Author Comment

by:dsoderstrom
ID: 35084030
The code I am using is as follows:

Dim iselecfile
    iselecfile = Dir("c:\Raw Material Spreadsheet.xls")
    If iselecfile <> "" Then
        Kill ("c:\Raw Material Spreadsheet.xls")
    End If
    DoCmd.OpenQuery "Clear Selected Comm Code List"
    DoCmd.OpenQuery "Load Selected Comm Code List-B"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Aluminum Extrusion", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Aluminum Sheet", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Hex Shaft", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Oval", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Angle", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Channel", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Pipe", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Round Tube", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Flat Bar", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Strip", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Expanded Metal", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Plate", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Sheet", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Plow Share-Beveled Bar", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Rectangular Tube", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Square Tube", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Round", "c:\Raw Material Spreadsheet.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Threaded Rod", "c:\Raw Material Spreadsheet.xls", True
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:dsoderstrom
ID: 35097085
Still don't know how to do this based on earlier reply.
I need to know what the code is for opening the Excel workbook and then stepping through the worksheets changing the column widths on each one.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35097313
to open the excel file using codes and set column widths

dim xlObj as object, j as integer
set xlObj=createobject("excel.application")
     xlobj.workbooks.open("c:\Raw Material Spreadsheet.xls")
     with xlObj
         for j=1 to .worksheets.count
              .worksheets(j).select
              .range("a:b").columnwidth=12              


         next
         .activeworkbook.save
     end with
     xlobj.quit
0
 

Author Closing Comment

by:dsoderstrom
ID: 35123651
This worked perfectly.  Thanks so much for the help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question