Solved

VBA Code Needs Revisions - Default Save Location

Posted on 2013-06-09
8
325 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
Comment Utility
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
Comment Utility
@ 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
Comment Utility
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
 
LVL 1

Author Comment

by:Geekamo
Comment Utility
To load "Dummy Data" into the Input worksheet, press CTRL + SHIFT + L.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
Comment Utility
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
Comment Utility
@ 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
Comment Utility
@ als315,

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

~ Geekamo
0
 
LVL 39

Expert Comment

by:als315
Comment Utility
You are welcome
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

762 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