Solved

Excel Default File Location

Posted on 2013-11-11
13
475 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
  • 8
  • 5
13 Comments
 
LVL 22

Accepted Solution

by:
Flyster earned 500 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
 

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 500 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 22

Assisted Solution

by:Flyster
Flyster earned 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

744 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

11 Experts available now in Live!

Get 1:1 Help Now