Results 1 to 3 of 3

Help with creating folder and saving file.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    102

    Help with creating folder and saving file.

    MY code is posted below. I need to create a folder with the name in cell "E10" of Sheet1. I then need to save a copy of sheet1 in it as a PDF with a name and timestamp (date & time). Any help would be greatly appreciated. I've been stuck on this for awhile. Thanks.

    Public Sub SaveToDesktop()
        
    Dim Value As String
        
     On Error GoTo MyError
    
    Set Value = Worksheets("Sheet1").Cells(10, "E").Value
    
    
    Filename1 = "C:\Users\" & Environ$("Username") & "\Desktop\" & Value
    Filename2 = "C:\Users\" & Environ$("Username") & "\Desktop\" & Value & "Sheet1" & Now() & ".pdf"
    
    'Checks for a folder
    Fdir = Filename
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    
    'Checks for a folder and creates it with the date
    Fdir = Filename
    
        Set FSO = CreateObject("Scripting.FileSystemObject")
         
        If Not FSO.FolderExists(Fdir) Then
             
            FSO.CreateFolder (Fdir)
             
        End If
    
    TheMessage = "Folder has been created named " & Filename
    
    
    
    Beep
    MsgBox TheMessage, vbInformation, "Folder Created"
    
    ThisWorkbook.SaveAs Filename2
    
    
    MyExit:
       Exit Sub
    'this handles an error for data mismatch
    MyError:
       If Err.Number = 13 Then GoTo MyExit
       MsgBox Err.Description
       GoTo MyExit
        
       
    End Sub
    Last edited by carden2; 09-06-2013 at 11:00 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Saving file to a specific folder
    By richkim2000 in forum Excel General
    Replies: 3
    Last Post: 04-17-2016, 11:32 AM
  2. [SOLVED] Saving a file to new folder dependant on the first letter of the file name.
    By G_La_Mood in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2012, 10:58 AM
  3. Creating a .txt file extracting information from a Excel file saving as .resx file
    By AbdallahHajbed in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2012, 09:00 AM
  4. creating a folder and saving in it with a filename taken from cell
    By dittotharappel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2009, 12:52 PM
  5. Saving CSV file and sending to a folder over and over again
    By scottymelloty in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-14-2009, 08:56 AM

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