Solved

VBA Code Needs Revisions - Default Save Location

Posted on 2013-06-09
8
346 Views
Last Modified: 2013-06-11
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
Comment
Question by:Geekamo
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:als315
ID: 39233206
Look at sample. Location is in A1 cell, list of possible values is in K1-K2.
SaveFile.xlsm
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39233226
@ 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
 
LVL 1

Author Comment

by:Geekamo
ID: 39233235
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Author Comment

by:Geekamo
ID: 39233237
To load "Dummy Data" into the Input worksheet, press CTRL + SHIFT + L.
0
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
ID: 39233249
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
 
LVL 1

Author Comment

by:Geekamo
ID: 39233782
@ 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
 
LVL 1

Author Comment

by:Geekamo
ID: 39237319
@ als315,

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

~ Geekamo
0
 
LVL 39

Expert Comment

by:als315
ID: 39238918
You are welcome
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now