+ Reply to Thread
Results 1 to 6 of 6

Cell Formatting with a Web Query

  1. #1
    Registered User
    Join Date
    08-26-2011
    Location
    Bath, UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Cell Formatting with a Web Query

    Hi,

    I have a vba web query which grabs some data formated on the web page as 01:03. Excel unhelpfully converts this to a time, eg 01:03:00, when I want to keep it in the original format.

    This is my web query -

    With ActiveSheet.QueryTables.Add(Connection:= "URL;" & URLVal1, Destination:=Range"$A$1"))
    .Name = "TEMP"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlOverwriteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = False
    .RefreshPeriod = 0
    .WebTables = "4"
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = False
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = True
    .WebDisableRedirections = True
    .Refresh BackgroundQuery:=False

    End With

    I've tried preformating the cells where the import occurs with a text format, but it doesn't fix it - I would have thought that the WebDisableDateRecognition property might have worked, but it doesn't.

    Any idea how I can set a particular column to preserve the original text formating?

    Thanks,
    David

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Cell Formatting with a Web Query

    After importing, loop through each cell to add an apostrophe which prevents Excel's automatic formatting:
    Please Login or Register  to view this content.
    Change rows and column as required.

  3. #3
    Registered User
    Join Date
    08-26-2011
    Location
    Bath, UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Cell Formatting with a Web Query

    Hi,

    Thanks for your reply - almost fixed it.

    What I didn't say in my original request was that some of the numbers can be bigger than 24 - eg 32:17. This causes the conversion using the HH:MM mask to return an incorrect value. 32:17 becomes 08:17 - I'm guessing because this is a day and 8 hours

    Any ideas on how I might solve this?

    Thanks
    David

  4. #4
    Registered User
    Join Date
    08-26-2011
    Location
    Bath, UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Cell Formatting with a Web Query

    I should also point out that what I actually want to do is split the imported text into two halves - so 37:17 would become 37 in one cell and 17 in another. Also, the numbers could be greater than 60 on both sides - so 84:76.
    Last edited by davidphi; 08-26-2011 at 10:07 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Cell Formatting with a Web Query

    Use the cell's .Text property instead of .Value and separate the parts with Mid or Split:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-26-2011
    Location
    Bath, UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Cell Formatting with a Web Query

    That's great - thanks for all your help! Problem fixed!

+ 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