+ Reply to Thread
Results 1 to 8 of 8

Assistance with Excel Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    4

    Assistance with Excel Macro

    Hi everyone, my first post.......

    This forum has been extremely helpful as a novice excel user and I hope someday I can return the favour and help somebody else.

    I have been trying to get some macros to work for and workbook we use to auto generate a job number in our work shop for a job card we use. Up until now it's been working well, where it simply generates the next job number and auto saves to file as that generated number into one folder location on our server.

    I'd like to now take this to the next level whereby it does what I just mentioned, but would like it to create a folder of the job number it just generated and save that file into that new folder. I have spent days looking through these forums, as well as Google but can't seem to find anything that works, and I just seem to get errors on what I try.

    The code I am currently using the generate the next job number and auto save the file with that number into a single folder location is as follows:

    This is the workbook code:

    Option Explicit
    
    Private Sub Workbook_Open()
    
        Dim strFileName As String
    
        With Sheet1.Range("C3")
            .Value = .Value + 1
            strFileName = .Value
        End With
        Me.Save
        
        'Me.SaveAs Filename:="C:\Temp3\" & strFileName
        
        Run "Create_Invoice"
        
        'optional code to close the main workbook after creating the invoice
        Me.Close
    
    End Sub

    This is the Module1 code:

    Option Explicit
    
    Sub Create_Invoice()
    
        Dim strFileName As String
    
        strFileName = Sheet1.Range("C3").Value
    
        ActiveWorkbook.Worksheets.Copy
        'the new workbook is now active
     
        With ActiveWorkbook
            Sheets(1).Name = strFileName
            .SaveAs Filename:="H:\JOB_FILES\CURRENT_JOBS\" & strFileName
        End With
    
    End Sub
    Any assistance and guidance would be greatly appreciated.

    Regards,
    Matt

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Assistance with Excel Macro

    all you need to add is MKDIR command to make the directory
    http://www.techonthenet.com/excel/formulas/mkdir.php

    not sure where along the line you want to plonk it in

    probably just before the save as in the create invoice macro?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    07-08-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Assistance with Excel Macro

    Quote Originally Posted by humdingaling View Post
    all you need to add is MKDIR command to make the directory
    http://www.techonthenet.com/excel/formulas/mkdir.php

    not sure where along the line you want to plonk it in

    probably just before the save as in the create invoice macro?
    Many thanks for your reply and feedback. How does this create a new directory for the file name that my original code has created ?? i.e; my code will generate a new job card/file with the next number, but I need it to now create new folder with that job number as its name and save file into it.

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Assistance with Excel Macro

    untested because it would take too much effort for me to setup this scenario

        With ActiveWorkbook
            Sheets(1).Name = strFilename
            MkDir "H:\JOB_FILES\CURRENT_JOBS\" & strFilename
            .SaveAs Filename:="H:\JOB_FILES\CURRENT_JOBS\" & strFilename & "\" & strFilename
        End With

  5. #5
    Registered User
    Join Date
    07-08-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Assistance with Excel Macro

    You my friend are an absolute legend !!! It works, thank you very much, I greatly appreciate this, thank you !

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Assistance with Excel Macro

    not a problem
    glad to help


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  7. #7
    Registered User
    Join Date
    07-08-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Assistance with Excel Macro

    Done. Again thanks for your help. I'm learning slowly and hopefully one day I can be of help to someone else.

    Cheers....

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Assistance with Excel Macro

    your coding seems good from what i can tell
    you seem to follow the good coding practices of idents etc
    makes life much easier for anything trying to follow

    just need more exposure to functions and how they can be applied really

+ 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. [SOLVED] Excel VBA Macro Assistance
    By kingsdime29x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2015, 06:21 PM
  2. Need assistance with a long macro involving multiple excel documents.
    By AJAllen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2013, 07:37 PM
  3. [SOLVED] Export Excel Tab to PDF. Macro Assistance Request!
    By spiwere in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 07-04-2013, 01:41 PM
  4. Macro assistance needed for complex export/import excel file
    By dedavie in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2013, 02:47 PM
  5. Assistance wth a MACRO
    By nick_w in forum Excel General
    Replies: 0
    Last Post: 02-29-2012, 11:42 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