Solved

VB Excel Object

Posted on 2002-05-29
3
138 Views
Last Modified: 2010-05-02
Hello,

I am writing an import routine to import data from an Excel spreadsheet into a SQL Server database.  The problem I am having is that one of the columns has a formatting on it and I can't retrieve the data as it appears.  Here is the info about this column:

Column name:         AS4TIME
Visual Appearance:   12:42:49
Fx (formula bar):    12:42:49 PM
Formatted as text:   0.529733796

My code is as follows:

pxlSheet.Cells(lngCurrentRecord, TIME_COL).Value
This returns:  0.529733796, which is unacceptable

so I tried:
pxlSheet.Cells(lngCurrentRecord, TIME_COL).Text
This returns: 12:42:49, which is what you see when you view the spreadsheet, but I need that 'PM' that appears in the formula bar.

I don't want to modify the sheet in any way.  Any help in retrieving 12:42:49 PM from this cell would be greatly appreciated
0
Comment
Question by:dentyne
  • 2
3 Comments
 
LVL 2

Expert Comment

by:Crin
ID: 7042788
Hi,

use CDate(pxlSheet.Cells(lngCurrentRecord, TIME_COL).Value)

Sincerely,
Crin
0
 
LVL 2

Accepted Solution

by:
Crin earned 100 total points
ID: 7042794
Sorry, forgot AM-PM issue:

Format(CDate(pxlSheet.Cells(lngCurrentRecord, TIME_COL).Value), "hh:mm:ss AMPM")

SIncerely,
Crin
0
 
LVL 1

Author Comment

by:dentyne
ID: 7042826
Hey that's great; thanks for the help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

912 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

18 Experts available now in Live!

Get 1:1 Help Now