+ Reply to Thread
Results 1 to 3 of 3

Date formatting cells w/ VBA

  1. #1

    Date formatting cells w/ VBA

    I am trying to format a cell when creating an excel spreadsheet from an
    access module. I would like to define the format of the cells from the
    vb code itself, but I don't know how exactly.

    Here is the pertinent code for how I am putting info into the cells
    from my DB:

    Dim oExcel As Excel.Application
    Dim oWorkbook As Excel.Workbook

    Set oExcel = CreateObject("Excel.Application")
    oExcel.Visible = True
    Set oWorkbook = oExcel.Workbooks.Add

    oWorkbook.ActiveSheet.Cells(1, 1).Value = "FirstName"
    oWorkbook.ActiveSheet.Cells(1, 2).Value = "LastName"
    oWorkbook.ActiveSheet.Cells(1, 3).Value = "Arrival Date"

    Anywho thanks, if anyone knows this. It seems like it should be
    simple, but web searching is only showing me GUI-based solutions.

    /r
    kkoechel


  2. #2
    Norman Jones
    Guest

    Re: Date formatting cells w/ VBA

    Hi K,

    To format A1:C1 as text, try:

    Cells(1,1).Resize(1,3).NumberFormat = "@"

    To format a cell as a date, try:

    Cells(!,2).NumberFormat = "mm/dd/yy"


    ---
    Regards,
    Norman



    <[email protected]> wrote in message
    news:[email protected]...
    >I am trying to format a cell when creating an excel spreadsheet from an
    > access module. I would like to define the format of the cells from the
    > vb code itself, but I don't know how exactly.
    >
    > Here is the pertinent code for how I am putting info into the cells
    > from my DB:
    >
    > Dim oExcel As Excel.Application
    > Dim oWorkbook As Excel.Workbook
    >
    > Set oExcel = CreateObject("Excel.Application")
    > oExcel.Visible = True
    > Set oWorkbook = oExcel.Workbooks.Add
    >
    > oWorkbook.ActiveSheet.Cells(1, 1).Value = "FirstName"
    > oWorkbook.ActiveSheet.Cells(1, 2).Value = "LastName"
    > oWorkbook.ActiveSheet.Cells(1, 3).Value = "Arrival Date"
    >
    > Anywho thanks, if anyone knows this. It seems like it should be
    > simple, but web searching is only showing me GUI-based solutions.
    >
    > /r
    > kkoechel
    >




  3. #3

    Re: Date formatting cells w/ VBA

    Thanks! Works great!

    Also, next time, I should probably do a quick googlegroups search as
    well, apparently I am not the first person to ask almost this exact
    same question =\

    the A1:C1 thing is going to be very helpful!

    kkoechel

    Norman Jones wrote:
    > Hi K,
    >
    > To format A1:C1 as text, try:
    >
    > Cells(1,1).Resize(1,3).NumberFormat = "@"
    >
    > To format a cell as a date, try:
    >
    > Cells(!,2).NumberFormat = "mm/dd/yy"
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > <[email protected]> wrote in message
    > news:[email protected]...
    > >I am trying to format a cell when creating an excel spreadsheet from an
    > > access module. I would like to define the format of the cells from the
    > > vb code itself, but I don't know how exactly.
    > >
    > > Here is the pertinent code for how I am putting info into the cells
    > > from my DB:
    > >
    > > Dim oExcel As Excel.Application
    > > Dim oWorkbook As Excel.Workbook
    > >
    > > Set oExcel = CreateObject("Excel.Application")
    > > oExcel.Visible = True
    > > Set oWorkbook = oExcel.Workbooks.Add
    > >
    > > oWorkbook.ActiveSheet.Cells(1, 1).Value = "FirstName"
    > > oWorkbook.ActiveSheet.Cells(1, 2).Value = "LastName"
    > > oWorkbook.ActiveSheet.Cells(1, 3).Value = "Arrival Date"
    > >
    > > Anywho thanks, if anyone knows this. It seems like it should be
    > > simple, but web searching is only showing me GUI-based solutions.
    > >
    > > /r
    > > kkoechel
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1