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

x
?
Solved

Excel Default File Location

Posted on 2013-11-11
13
Medium Priority
?
555 Views
Last Modified: 2013-11-12
Experts:

In Excel, how can I define both "default file location" and "default filename" through VBA.

I do >> NOT << want to use the  "Tools | Options | General" to set the default location.

Essentially, the spreadsheet (.XLT) would be used by multiple individuals... they all have to save it to the same location with the same filename (thus replacing existing files in the default subfolder).

Ideally, there would be a macro button on the worksheet (.XLT) ... once clicked the content of the .XLT would then be saved as an .XLS without them even having to specify name/location.

Is that doable?  If so, how can this be done via VBA?

EEH
0
Comment
Question by:ExpExchHelp
[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
  • 8
  • 5
13 Comments
 
LVL 22

Accepted Solution

by:
Flyster earned 2000 total points
ID: 39640128
Here's a macro that will save your xml file as a xls in the location and name you define in Filename =. It will automatically overwrite previous editions without warnings. If you want the warnings, just remove the first and last lines.
Sub SaveAsXls()

  Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Enter\Path\Here\YourFileName.xls", FileFormat:= _
        xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
  Application.DisplayAlerts = True
  
End Sub

Open in new window

Flyster
0
 

Author Comment

by:ExpExchHelp
ID: 39640147
Flyster:

Thanks for the prompt reply.    Just a few clarifications questions...

1. Where in the VBA should I save the code?  
- ThisWorksheet? or
- Sheet1? or
- Modules|Modules1

2. How can I link the code to a command button which should be located, e.g., in cell A1?

Thanks in advance for the continued help.

EEH
0
 
LVL 22

Expert Comment

by:Flyster
ID: 39640190
1. This should be placed in a module in your template file.

2. In design mode, right-click your command button. If it's a legacy command button, there will be an option to assign a macro to the button. If it's an active-x command button, select "View Code" and paste it there.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ExpExchHelp
ID: 39640211
Thanks...

When running the macro, I get a compile error.

Please see attached XLT and JPG.

How can I fix the compile error?

EEH
Test.xlt
CompileError.jpg
0
 
LVL 22

Assisted Solution

by:Flyster
Flyster earned 2000 total points
ID: 39640282
My apologizes, I was using Word 2007. Try changing FileFormat:=xlExcel8 to FileFormat:=xlNormal
0
 

Author Comment

by:ExpExchHelp
ID: 39640334
Great... that works.   Excellent!

I only forgot to mention one thing earlier.   In the XLS that is copied, I need to have the command button removed (i.e., all content will be copied except the command button).

I have something similar in MS-Word where the line (see below) removes the shape (i.e, the command button in Word):

doc.Shapes(1).Delete

Can I use something similar in Excel to remove that shape as well?   If yes, that's line of code?

EEH
0
 
LVL 22

Assisted Solution

by:Flyster
Flyster earned 2000 total points
ID: 39640398
Try this after the first line:

    ActiveSheet.Shapes("CommandButton1").Select
    Selection.Delete

Change"CommandButton1" to the name of your command button.
0
 

Author Comment

by:ExpExchHelp
ID: 39640458
MOST EXCELLENT!!   Works like a charm!

** Break **

Now I have to do the same for a PowerPoint file.  I'll post another thread tomorrow and will provide the URL here... in case you're willing to assist (tomorrow).

Cheers,
EEH
0
 
LVL 22

Expert Comment

by:Flyster
ID: 39640475
I'll keep my eye out for it! Thanks
0
 

Author Comment

by:ExpExchHelp
ID: 39640476
Flyster:

Actually, I already opened up the thread... pretty much the same approach, except this process is focused on PowerPoint vs. Excel.

Below is the new thread:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Powerpoint/Q_28291456.html

I'd welcome if you have any suggestion on this topic.

EEH
0
 

Author Comment

by:ExpExchHelp
ID: 39641423
Flyster:

Quick follow-up... what's the VBA code for deleting a command button in MS-Word?

Cheers,
EEH
0
 

Author Comment

by:ExpExchHelp
ID: 39641447
That is... currently I use a shape (rectangle) vs. actual command button.   The current code is:

Private Sub CommandButton1_Click()
    Dim doc As Document
    Set doc = ActiveDocument
    doc.Shapes(1).Delete
    doc.SaveAs "C:\KTG_Testing\DailyWatchOrder.doc"
End Sub

However, having used a command button in Excel and PowerPoint, this is now the preferred method.   Based on the existing code, deleting the command button in Word does work though.

Any thoughts/recommendations?

EEH
0
 

Author Comment

by:ExpExchHelp
ID: 39641516
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

636 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