Automatically save file to specific folders base on cell name????

  • Hey so i will try my best to describe my intentions here

    I have an invoice setup with 4 buttons on the side, one to save as a excel file, second to save as a pdf file and the 3rd button sends a pdf as an email through outlook. the 4th button just clears specific cells in the invoice.


    When i save the the file it copies values in specific cells and saves it in a specific folder


    for example


    "Invoice"(B3), "900"(F5), "Business Name"(B13(merged)C13)


    Looks like this:


    "Invoice 900 Business Name"


    So, is it possible to tweak this to have the same save options but the "business name "will automatically save to the related business name sub folder if changed in excel.


    i hope that makes sense

  • When you save normally it would be:

    Save PathName & FileName


    It could be:

    PathName is: "C:\Invoices\"

    FileName is: "Invoice"(B3), "900"(F5), "Business Name"(B13(merged)C13)


    Becomes something like:

    Save "C:\Invoices\" & "Business Name"(B13(merged)C13) & "\" & "Invoice"(B3), "900"(F5), "Business Name"(B13(merged)C13)

  • External Content www.youtube.com
    Content embedded from external sources will not be displayed without your consent.
    Through the activation of external content, you agree that personal data may be transferred to third party platforms. We have provided more information on this in our privacy policy.


    this is what I want to do in general

  • thats where im stuck lol no idea how to adapt the coding to my existing file via vba, but i can figure out where to setup "path to save to" and "path lookup" from the example of the video. here is the coding currently using


    1 Sub EmailAspdf()

    2

    3 Dim EApp As Object

    4 Set EApp = CreateObject("Outlook.application")

    5

    6 Dim Eitem As Object

    7

    8

    9 path = "C:\Users\xrurk\Google Drive\Junk Alert Office Work\Accounting\Invoices\"

    10 invno = Range("F5")

    11 invna = Range("B3")

    12 address = Range("B22")

    13 custname = Range("B13")

    14 fname = invna & " " & invno & " - " & custname

    15

    16 ActiveSheet.ExportAsFixedFormat _

    17 Type:=xlTypePDF, _

    18 IgnorePrintAreas:=False, _

    19 Filename:=path & fname

    20

    21 Set Eitem = EApp.CreateItem(0)

    22

    23 With Eitem

    24

    25 .To = Range("B16")

    26 .Subject = " " & address & " - " & invna & " " & invno

    27 .Body = "Please Find Invoice Attached. If Paying By E-Transfer, Please Add Invoice Number or Address In the comment section of the E-Transfer!"

    28 .Attachments.Add (path & fname & ".pdf")

    29 .Display

    30

    31 End With

    32

    33 End Sub

    34

    35

    36 Sub SaveAspdf()

    37

    38 Dim invno As Long

    39 Dim invna As String

    40 Dim address As String

    41 Dim custname As String

    42 Dim path As String

    43 Dim fname As String

    44

    45 path = "C:\Users\xrurk\Google Drive\Junk Alert Office Work\Accounting\Invoices\"

    46 invno = Range("F5")

    47 invna = Range("B3")

    48 address = Range("B22")

    49 custname = Range("B13")

    50 fname = invna & " " & invno & " - " & custname

    51

    52 ActiveSheet.ExportAsFixedFormat Type:=x1TypePDF, IgnorePrintAreas:=False, Filename:=path & fname

    53

    54 End Sub

    55

    56 Sub saveinvasExcel()

    57

    58 Dim invno As Long

    59 Dim invna As String

    60 Dim address As String

    61 Dim custname As String

    62 Dim path As String

    63 Dim fname As String

    64

    65 path = "C:\Users\xrurk\Google Drive\Junk Alert Office Work\Accounting\Invoices\"

    66 invno = Range("F5")

    67 invna = Range("B3")

    68 address = Range("B22")

    69 custname = Range("B13")

    70 fname = invn2 a & " " & invno & " - " & custname

    71

    72 'copy the invoice sheet to a new workbook

    73

    74 Sheet1.Copy

    75

    76 'then delete all the buttons on the worksheet

    77

    78 Dim shp As Shape

    79

    80 For Each shp In ActiveSheet.Shapes

    81 If shp.Type <> msoPicture Then shp.Delete 'This line is modified so that is doesn't delete the logo

    82 Next shp

    83

    84 'save the new workbook to a specified folder

    85 With ActiveWorkbook

    86 .Sheets(1).Name = "Invoice"

    87 .SaveAs Filename:=path & fname, FileFormat:=52

    88 .Close

    89 End With

    90

    91

    92

    93 End Sub

  • To save the file in a specific folder (B13=custname) change the line that saves it to:

    .SaveAs Filename:=path & custname & "\" & fname, FileFormat:=52


    Ps. the custname folder must already exist.

    Edited once, last by rollis13 ().

  • i figured it out!!!!!


    took me awhile i added this


    64 Dim wb2 As Workbook

    65 Dim ws2 As Worksheet


    66 Set wb2 = ThisWorkbook

    67 Set ws2 = wb2.Worksheets("Business Contacts")


    and changed this


    68 path = ws2.Range("F2")


    87 SaveAs Filename:=fname, FileFormat:=52


    not sure how i did it!!! thank you for the help though

  • now im stuck here, cant figure out how to save as a pdf file to the same folder


    36 Sub SaveAspdf()

    37

    38 Dim invno As Long

    39 Dim invna As String

    40 Dim address As String

    41 Dim custname As String

    42 Dim path As String

    43 Dim fname As String

    44

    45 path = "C:\Users\xrurk\Google Drive\Junk Alert Office Work\Accounting\Invoices\"

    46 invno = Range("F5")

    47 invna = Range("B3")

    48 address = Range("B22")

    49 custname = Range("B13")

    50 fname = invna & " " & invno & " - " & custname

    51

    52 ActiveSheet.ExportAsFixedFormat Type:=x1TypePDF, IgnorePrintAreas:=False, Filename:=path & fname

    53

    54 End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!