+ Reply to Thread
Results 1 to 6 of 6

Macro to select cells and save as html

  1. #1
    Registered User
    Join Date
    12-24-2010
    Location
    WV
    MS-Off Ver
    Excel 2003
    Posts
    8

    Thumbs up Macro to select cells and save as html

    HI guys,
    I am hoping that some one can help me with this. Have been looking everywhere and cant seem to get the right answer.

    Here is what I have:

    Sheet1 has several rows of data then one empty row. Then I have several rows of data and an empty row. This continues for about 100-150 times (this varies each week)

    Here is what I am trying to do.

    I need the macro to be able to select from A1 to the last row:column that has data so that I can apply borders (keep in mind that last row:column will always not be the same cell since number of rows varies).

    Then I would like to save the selection as html file and file name should be whatever value I have on a1 (so if I have Jan012011 in A1, it needs to be Jan012011.htm)

    I would greatly appreciate if anyone could help me with that. I have found couple of vbscript to select the cells, however because I have empty rows, those only selects first set of rows. I need the script to go all the way to the last cell that has any data.

    Thanks for your help
    Last edited by itmanusa; 12-27-2010 at 09:21 AM. Reason: Solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro to select cells and save as html

    Hello itmanusa,

    Welcome to the Forum and Merry Christmas!

    This macro will create a HTML file for the range in column "A" and name the file using the contents of cell "A1".

    Please Login or Register  to view this content.

    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Last edited by Leith Ross; 12-24-2010 at 08:07 PM. Reason: Added salutation
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-24-2010
    Location
    WV
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Macro to select cells and save as html

    Hi Leith,
    Thank you so much for providing this. However I couldnt get this to work for some reason. I am not sure if I wasnt able to describe what I really wanted or not. Any way, I got the below code from a friend which lets me select the range of data on the spreadseet (This sheet is called "datapage"). I have data in rows A1:H?. If I use this code below, I can select the dynamic range of data. Now the problem I have is that I need to be able to publish this selected range of data as web page and have the web page name to be derived from sheet called "Main" and cell A25. This cell actually already have the file name (ex 122410.htm). This name changes when I open the file so I just need the file name to reference to this cell.

    Hope this makes more sense and appreciate any help you can provide.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-10-2010
    Location
    Hong Kong
    MS-Off Ver
    Excel 97
    Posts
    13

    Question Re: Macro to select cells and save as html

    Hi, Leith Ross.
    Excuse me, I have a few questions to ask.
    Because I wonder I use some 'old style' of coding to do.
    What is the difference and which can be easier on debug?

    If user want to cap more the one column with different type of HTML tag show.
    such as Column B to be Date Format YYYY/MM/DD, Column C to be Red in color in -ve.

    As you see, my code as if MS-DOS aged..

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro to select cells and save as html

    Hello itmanusa,

    I made some changes to the macro. It now looks at columns "A:H" and finds the last entry. The file will now be created if it doesn't exist.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 12-25-2010 at 01:23 AM.

  6. #6
    Registered User
    Join Date
    12-24-2010
    Location
    WV
    MS-Off Ver
    Excel 2003
    Posts
    8

    Thumbs up [SOLVED] Macro to select cells and save as html

    Leith,
    I would like to thank you once again for the code. It worked just as I needed it to work. I did have to make a little change for the file to be saved. I had to hard code the destination location, for some reason the current directory location only worked once. Every time after that I couldn't get it to work until I typed the whole path.

    Once again thanks a lot and happy new year to you.

    Your code:
    Please Login or Register  to view this content.
    I changed to:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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