• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

VBA Code Needs Revisions - Default Save Location

Hello Experts,

I am currently using this code,...

Sub BuildFileNameAndSave()
    
    Dim SaveStr As Variant
    Dim ws As Worksheet
    
    Set ws = ThisWorkbook.Worksheets("Input") 'change as needed
    
    SaveStr = False
        
    Do Until SaveStr <> False
        SaveStr = Application.GetSaveAsFilename(CurDir & "\LOT # " & ws.[LotNumber] & " - CUST # " & ws.[CustomerNumber] & " - " & UCase(ws.[CustomerName]) & ".xlsm", "Excel Workbooks (*.xlsm), *.xlsm", , _
            "Select file name and folder:")
        If SaveStr = False Then
            SaveStr = MsgBox("Please make a selection!", vbRetryCancel)
        End If
        If SaveStr = 4 Then SaveStr = False
    Loop
    If SaveStr <> 2 Then
        ThisWorkbook.SaveAs SaveStr
    End If
End Sub

Open in new window


I have a few alterations I would like in the code above, I just have no idea how to code them myself.  (I have done some searching and found other codes, that somewhat do what I'm looking for.  But I don't know how to incorporate them into my existing code.)

Item 1:

When running this macro, user is presented with a dialog box that says,...

Title:  Save Version
Body:  "You are about to save a copy of this file, named - 'LOT # 439648 - CUST # 496331 - PICKLE SHOP.xlsm' to the network folder.  Do you wish to continue?" YES/NO

Please Note:  The file name in my example above, is figured out by the code in my VBA. So I assume the dialog box will have that line of code copied into it as well?

Item 2:

I would like the default save location to be,...

(local folder)
C:\Users\PC\Dropbox\Pallet Tag Generator\

But come Monday, I will be changing the location to something like,...

(network folder)
Z:\XXXX\XXXX\

Item 3:

After the save is completed, I would like the workbook (NOT EXCEL ITSELF - user might be working in other workbooks) to automatically close.

Item 4:

Upon closing of the workbook, I would like Windows Explorer to automatically open - to the default save location.

Item 2 - is the MOST important to me, and the others would only be extras for me.

I hope they're all possible, but I have a feeling Item 4, isn't possible?

If you have any questions, please let me know.  I will be following this post closely as I need this completed very soon. So if you respond, I should have a response back to you within minutes.

Thank you in advance for your help.

~ Geekamo
0
Geekamo
Asked:
Geekamo
  • 5
  • 3
1 Solution
 
als315Commented:
Look at sample. Location is in A1 cell, list of possible values is in K1-K2.
SaveFile.xlsm
0
 
GeekamoAuthor Commented:
@ als315,

Hmm, the example workbook is not working correctly for me.  When I click on the command button, it doesn't have the C:\temp location already in view, it's just defaulting to My Documents, like it always has.  Also the window explorer window only opens to My Documents.

Ideally, I would prefer the default location to be hard coded in code, instead of being within a cell.

Would it be more helpful if I posted the actual workbook?
0
 
GeekamoAuthor Commented:
The file is attached.

Again, item # 2 - is the most important to me.  I could live without the others, (although it would be nice to have all of them coded in)

As for # 2, I'd prefer the location be hard coded into the code - and not within a cell on the spreadsheet.

~ Geekamo
Pallet-Tag-Generator.xlsm
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
GeekamoAuthor Commented:
To load "Dummy Data" into the Input worksheet, press CTRL + SHIFT + L.
0
 
als315Commented:
If target folder do not exist, you will be moved to default folder (My Documents). Place correct path to list source. Look at sample based on uploaded file
Pallet-Tag-Generator.xlsm
0
 
GeekamoAuthor Commented:
@ als315,

Oh, I assumed that if the directory/folder wasn't there it would of created it.  Anyhow not an issue. I created the temp folder and your code works flawlessly!

I'm going to try to incorporate this into my actual workbook - and I'll take a stab at coding the location directly in, instead of being within a cell.

I'll post back shortly.

~ Geekamo
0
 
GeekamoAuthor Commented:
@ als315,

This has worked out great!  Thank you again for your help als315 - I appreciate it!

~ Geekamo
0
 
als315Commented:
You are welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now