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
Solved

Format Excel Columns as Text from MS Access using VBA

Posted on 2013-10-25
5
7,561 Views
Last Modified: 2013-10-27
I need to format two Excel columns as text from MS Access using VBA. Any thoughts.
0
Comment
Question by:shieldsco
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39601875
You need to open the Excel Workbook and then format two columns?

The following will open PATH/Name.xls and format Columns A through B as Text on the first Sheet:

    Set objApp = CreateObject("Excel.Application")
        objApp.Visible = True
        Set wb = objApp.Workbooks.Open("PATH/Name.xls", True, False)
    
    wb.Sheets(1).Range("A:B").NumberFormat = "@"

Open in new window


Change the PATH/Name.xls to your Excel File, the number of the Sheet, then the Column(s).
0
 

Author Comment

by:shieldsco
ID: 39603761
Works good but how do I save the workbook and close the application
0
 
LVL 18

Accepted Solution

by:
Steven Harris earned 500 total points
ID: 39603935
    Set objApp = CreateObject("Excel.Application")
        objApp.Visible = True
        Set wb = objApp.Workbooks.Open("PATH/Name.xls", True, False)
    
    wb.Sheets(1).Range("A:B").NumberFormat = "@"
    
    wb.SaveAs "PATH/Name.xls"
    wb.Close
    Set objApp = Nothing

Open in new window

0
 

Author Comment

by:shieldsco
ID: 39604226
How do I close the Excel application?

Private Sub Command0_Click()
 Set objApp = CreateObject("Excel.Application")
        objApp.Visible = True
        Set wb = objApp.Workbooks.Open("C:\Users\ShieldsCo\Documents\Change Text.xlsx", True, False)
   
    wb.Sheets(1).Range("A:B").NumberFormat = "@"
    wb.Save
    wb.Close
 
    Set objApp = Nothing
   
End Sub
0
 

Author Closing Comment

by:shieldsco
ID: 39604262
Thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

765 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