export to xls vba

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
318
Hi excel gurus,

I have the following code which works perfectly:

Code:
Sub export_lionbridge()


Dim New_file_name


New_file_name = Application.GetSaveAsFilename(, "Microsoft Excel Workbook (*.xls), *.xls")
Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs FileName:=New_file_name, FileFormat:=xlNormal
ActiveWindow.Close


 Application.Calculation = xlCalculationAutomatic
     Application.ScreenUpdating = True
 
End Sub

The code copies a worksheet and allows a user to save it as an XLS file, all I need help on is to disable the "Save As" user prompt, I want the file to be saved automatically to the desktop i.e C\Users\Desktop and the name of the file to be referenced from Sheet2 cell A1.

Is this possible, if so how?

Thank you!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Sub export_lionbridge()  
Dim New_file_name
Dim Path As String
Path = CreateObject("Wscript.Shell").specialfolders("Desktop") & "\"
New_file_name = Path & Sheet2.Range("A1").value
Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs FileName:=New_file_name, FileFormat:=xlNormal
ActiveWindow.Close  
 Application.Calculation = xlCalculationAutomatic    
 Application.ScreenUpdating = True 
 End Sub
 
Last edited:
Upvote 0
Perfect, thank you Starl! :)

I do have one other question though, I have modified the code slightly to include this:

Code:
New_file_name = Path & Sheets("Home").Range("F6").Value & "_export"

But sometimes the value F6 has spaces between the words, would it be possible to replace the space characters with underscores?

Thank you!
 
Upvote 0
Try this.
Code:
Sub export_lionbridge()
Dim strNew_file_name As String
Dim strPath As String

    strPath = CreateObject("Wscript.Shell").specialfolders("Desktop") & "\"
    strNew_file_name = Replace(Sheets("Home").Range("F6").Value & "_export", " ", "_")
    
    Sheets("Sheet1").Copy
    
    With ActiveWorkbook
        .SaveAs Filename:=strPath & strNew_file_name, FileFormat:=xlNormal
        .Close
    End With
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top