Solved

Format Excel Columns as Text from MS Access using VBA

Posted on 2013-10-25
5
6,904 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now