Save Excel Workbook to user's desktop in text format

Aashna

New Member
Joined
Jun 17, 2015
Messages
19
Hi there,

I've an Excel Workbook (SAP Upload File) that has an Export Button, on clicking it I want to ave a copy of that active worksheet to the user's desktop. After running the below code it is showing a compile error 'Expected End with'.
If someone could check this out would be awesome. Please let me know if you need any further information.

Thanks!
____________________________________________________________________________
Sub Export()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String


With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Save file to users desktop
Dim TempFilePath As String
Dim TempFileName As String
Set Destwb = ActiveWorkbook

TempFilePath = "C:\Users\" & Environ$("Username") & "\Desktop\"
TempFileName = fName & "_allocation"
FileExtStr = ".txt": FileFormatNum = -4158

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum
On Error Resume Next
On Error GoTo 0
.Close savechanges:=False
End With
'Change all cells in the worksheet to values if you want
If Destwb.Sheets(1).ProtectContents = False Then
With Destwb.Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
Application.CutCopyMode = False



'Save the new workbook and close it
With Destwb
fName = Range("G1").Value

ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("Username") & "\Desktop\" & fName & "_Advanced_Ladder_upload" & "_R" & "_" & SectionYear & SectionMonth & SectionDay & SectionHour & SectionMinute & SectionSecond & "", _
FileFormat:=xlText, CreateBackup:=False




MsgBox "You can find the files in " & FolderName


With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
 
This line is ok. Maybe you have an open parenthesis on a line above this statement.

Comment this msgbox statement and try to run your code.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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