Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA Code Needs Revisions - Default Save Location

Posted on 2013-06-09
8
Medium Priority
?
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

610 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