+ Reply to Thread
Results 1 to 9 of 9

VBA: Tweak Export to HTML code to create folder on desktop and save there?

  1. #1
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    213

    Question VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Hi all,

    I am using the following code to export a range of cells (with HTML content) to one consolidated HTML file.
    This used to work perfectly until I moved all of my data to OneDrive. Not it seems like VBA doesn't have permissions anymore to write to the same path as the .xlsm is in (which sits in OneDrive)?

    I'm wondering, is there a way to tweak this code to use the filepicker instead so I can choose a non-OneDrive folder to save the HTML?

    At the moment, the below code only works if the .xlsm is saved in a non-OneDrive location (e.g. Desktop).

    The code is:

    Please Login or Register  to view this content.
    Hope someone can help this VBA newbie here?
    Thanks!

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    213

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Hi Kenneth,

    Thanks so much! This seems to give me a message with the path to the desktop, but could you help me understand how I can tweak the code to use the file picker to create/select a folder (that's not on OneDrive) to save my file there?
    At the moment, the code saves in the same location as the .xlsm, which doesn't seem to work (as that sits in a shared environment).

    Appreciate the help!
    Thank you!

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    213

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Hey Kenneth,

    Great, thank you! This does not use file picker, but can also work with creating a folder directly on desktop Thank you!
    I tried to apply the updates to a similar code (which is to export individual files rather than one, consolidated file) and I got it to work, however, it's only creating 0kb files without a file extension at the moment (file names are correct though)...do you have any idea what I might be doing wrong? Tried a few things without luck, sadly...

    Please Login or Register  to view this content.
    Thanks so much!

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    I have not used that method. Can you attach a simple example to test?

    If you did Debug.Print filename, does it show the right filename string in Immediate Window?

  7. #7
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    213

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Hey Kenneth,

    Sure thing! Attached - hope this helps?

    As said, it seems to be creating files, but just not writing anything to them :-(

    Thanks so much for your help!
    Attached Files Attached Files

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Sorry, just got time to look at this again.

    When building filenames with dates and times, be sure that they are legal filenames. e.g. Do not use \/:*"<>|

    You can use Format() to change datetime to a legal filename string. A Debug.Print filename is how I found:
    C:\Users\ken\Desktop\Test\HTMLImportName_Test1_16-03-2021_11:02.html

    Or, use Replace() to replace the colon character.
    Last edited by Kenneth Hobson; 03-16-2021 at 08:22 PM.

  9. #9
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    213

    Re: VBA: Tweak Export to HTML code to create folder on desktop and save there?

    Hi Kenneth,

    Ahhh, good spot! I did not think about that! Thanks so much! Changed the file name and this works now Yaaay!

    Thanks again and have a great day!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Create Folder & Check if Folder Exists if Not Create Folder & then Save File
    By Quivolt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2017, 05:31 AM
  2. [SOLVED] VBA Code to create folder on desktop
    By Liz_Biz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2014, 11:19 AM
  3. [SOLVED] VBA: Create a new folder on any users desktop and save the file as value in cell (A51)
    By nwb in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-24-2014, 11:02 PM
  4. Create a VBA code that creates a shortcut folder on desktop.
    By samdegg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2013, 12:26 PM
  5. Code to create New Folder (if doesn't exist) and then Save Workbook to folder
    By jenhawley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-10-2013, 03:09 PM
  6. VBA Export worksheet to CSV and save on desktop
    By jph89 in forum Excel General
    Replies: 0
    Last Post: 08-30-2012, 11:55 AM
  7. [SOLVED] save as CSV file on desktop but in a 'New folder'
    By mike02 in forum Excel General
    Replies: 6
    Last Post: 08-15-2012, 05:25 PM

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