VBA - Exporting to Excel

ClaireLou

New Member
Joined
Nov 14, 2020
Messages
12
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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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