Solved

Format Excel Columns as Text from MS Access using VBA

Posted on 2013-10-25
5
8,207 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
[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
  • 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
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.

717 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