New data file created through VBA can't be imported

dweingar16

New Member
Joined
Oct 17, 2017
Messages
3
I am creating a data file in excel that creates a spreadsheet in my primary workbook (Main), then cleans it up, and then creates a new workbook named test.xlsx that the data is pasted into. When I try and import the data from the test.xlsx file into another application it does not work. If I copy and paste the data from test.xlsx into a file with a name other than test.xlsx, it works. Help. This is the VBA code that is creating the new workbook.

Dim FName As String
Dim FPath As String

Dim wb As Workbook
Set wb = Workbooks.Add
Set xls = CreateObject("Excel.Application")
xls.DisplayAlerts = False
ThisWorkbook.Sheets("Main").Copy Before:=wb.Sheets(1)
'Clean up
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("I:Z").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
'sbDelete_Rows_IF_Cell_Contains_String_Text_Value()
Dim lRow2 As Long
Dim iCntr2 As Long
lRow2 = 390
For iCntr2 = lRow2 To 1 Step -1
If Cells(iCntr2, 6).Value = "0" Then
Rows(iCntr2).Delete
End If
Next
' ActiveSheet.Shapes.Range(Array("Button 1")).Select
' Selection.Delete

wb.SaveAs "H:\Test.xlsx", AccessMode:=xlExclusive, ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges
ActiveWorkbook.Close
wb.Close (True)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I changed the SaveAs file name to Test1.xlsx and it worked to import the file. Any idea what I need to do to clear out the system as to why it won't import Test.xlsx?
 
Upvote 0
It works when you call the file Test1.xlsx but not when you call it Test.xlsx?

You say "When I try and import the data from the test.xlsx file into another application it does not work."

What is this other application? And what is the error message, or how does it not work?

Also, the file that doesn't work (Test.xlsx), can you open it in Excel? If you can, the problem sounds like it's with the other application.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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