VBA - Exporting to Excel

ClaireLou

New Member
Joined
Nov 14, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi
I have a master document that we're using to produce statements for Customers.

I need to pull out the various statements into other excel sheets but I've managed to write it as PDF and I cant get them to come out as excel files. I will also end up having to add an array to pull 2 tabs but I need the VBA to work first.

Am I doing something glaringly obviously wrong? I thought it was the fixed format but can't find what it should be. Code is below.

Thanks

Claire

Private Sub CommandButton1_Click()
On Error Resume Next
Dim i As Long
Dim sCount As String
Dim vSAMPLE1 As Variant
Dim SAMPLE2 As Variant
Dim isheet As Worksheet

Set isheet = ThisWorkbook.Sheets("Sample Sheet")
vSAMPLE1 = [CUSTOMERS]
i = UBound(vSAMPLE1)
If i > 1 Then
sCount = i & " client "
Else: sCount = i & " client "
End If

If MsgBox("A statement for " & sCount & "will be exported." _
& vbCr & "Do you want to continue?", vbYesNo + vbDefaultButton2 + vbQuestion, _
"Sample Sheet") = vbYes Then
With Sheet2
For i = 1 To i
[CUSTOMERS] = vSAMPLE1(i, 1)
CUSTOMERS = [SAMPLE1] & ".xlsx"
ThisWorkbook.Sheets("Debt Statement").Select
ActiveSheet.ExportAsFixedFormat Type:=x1Normal, _
Filename:="C:\Users\MYFOLDER\MYFILES\" & CUSTOMERS, _
IgnorePrintAreas:=False, OpenAfterPublish:=False

Next
End With
End If
MsgBox "Complete"
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,148,144
Messages
5,745,044
Members
423,917
Latest member
Frank1931

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
Top