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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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