Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBA Code Needs Revisions - Default Save Location

Posted on 2013-06-09
8
Medium Priority
?
376 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 40

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

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

Accepted Solution

by:
als315 earned 2000 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 40

Expert Comment

by:als315
ID: 39238918
You are welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

564 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