Wrox Programmer Forums
|
VB Components Issues specific to components in VB.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2007, 06:07 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel Object in VB

Can I reformat a worksheet column to a particular format?

In particular, my sheet is an export from another application and it's got the dates in a pickle ... the data in the columns show things like 37961, 38265, etc.,

I can select the whole column (in Excel) and change it to "date format", which shows the data correctly as 6/12/2003, 5/10/2004, etc. and it is this, that I need to do from within VB.

Regards,

Sean Anderson
__________________
Regards,

Sean Anderson
 
Old May 1st, 2007, 12:08 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I recorded a macro in Excel, selected column A, right-clicked a cell, selected format cells, and set the format to Date. The resultant macro had the folowing code:
Code:
    Columns("A:A").Select
    Selection.NumberFormat = "mm/dd/yy"
    If you create a reference to Excel using CreateObject() or GetObject(), you should be able to use this action with the .ActiveWorkbook.
 
Old May 2nd, 2007, 03:19 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used the following workround:

Range(oMySheet.Cells(2, nColumnNumber), oSheet.Cells(oSheet.Rows.Count, nColumnNumber)).NumberFormat = "dd/mm/yyyy"

I will have a look at using the "SELECT" within VB and see if I can do something clever there.

I can't get to a macro that's been recording in Excel, because it won't exist in the final version. The application is for a client who generates the spreadsheet from their system and then runs it through my application, you see.

Regards,

Sean Anderson
 
Old May 3rd, 2007, 03:20 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The reason I mentioned recording macros in Excel was not to keep them in Excel, but to have Excel reveal to you the way to do in code that which you did with the regular user interface, so that you can then adapt that way of doing things to your VB project.





Similar Threads
Thread Thread Starter Forum Replies Last Post
converting .NET error object in VB error object webnet .NET Web Services 0 February 5th, 2007 06:02 AM
Excel Object dpkbahuguna Beginning VB 6 0 January 29th, 2007 01:51 AM
Using Excel Chart Object in VB App John Pennington Beginning VB 6 1 July 12th, 2006 01:39 PM
Printing using EXCEL object Bruce Pro VB 6 0 January 14th, 2005 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.