Code Crashes on WinXP

Anne Troy

New member
Joined
Mar 25, 2011
Messages
23
Reaction score
0
Points
0
And I can't figure out why!! I did ask this on MrExcel with no real response.

Code:
Sub SaveForImporting()
ThisWorkbook.SaveAs "C:\MImport" & ".xls", FileFormat:=56
ActiveWorkbook.Close False
End Sub

Help!! Thanks and Hi, Ken!

Yes, I have rights to root.
The file format is xlsm before saving. I don't *need* a macro-free workbook, I just need xls so the SQL that's going to use the data works right.
 
Last edited:
Code:
Sub SaveForImporting()
Dim strFileName As String
strFileName = "MyBook"
ThisWorkbook.SaveAs "C:\MImport\" & strFileName & ".xls", FileFormat:=56
ActiveWorkbook.Close False
End Sub

Oops, just realised that you want to save to C:\ and file name is MImport.xls. I don't know why you can't do it. It works for me :(
 
Last edited:
Anne, I'm just booting up a VM running Windows XP. What version of Office are you running? 2007 or 2010? The code is called from an xlsm file, but trying to save in an xls format, is that right?
 
Hmmm... have to ask... are you SURE you have rights to create files in the root of C:\ on your system? Like Ed, it's working fine for me as you posted.

Maybe there is something else in the code that is causing a conflict, or the file is corrupt?
 
Hi, Ken! Thanks and sorry for the delay. Yes. We have rights to C. Everything works perfectly. Except the error AFTER it saves the file. I'm saving as XLS extension. Don't care whether there's code in the file or not or what the *actual* file type is.

Very weird.

Code:
Sub SaveToC()
Application.DisplayAlerts = False
If Len(Dir("C:\Users\", vbDirectory)) = 0 Then
ThisWorkbook.SaveAs "C:\FLImport" & ".xls", FileFormat:= _
        xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
ActiveWorkbook.Close False
Else: MsgBox ("No Way!" & Chr(13) & "You are not on a virtual machine." & Chr(13) & Chr(13) & "Para nada!" & Chr(13) & "Tu no estas en una maquina virtual."), vbOKOnly
End If

Application.DisplayAlerts = False

End Sub

Hoping this forum takes code tags.
 
Okay, so what is the error exactly? What line is highlighted?

This code is now checking to make sure that the C:\Users folder doesn't exist, and tries to save the file as an xls if true. That's correct?
 
Yes, but that doesn't matter. It crashed before that was there. We perform programming of a sort on virtual machines. The workbook is usually worked on the regular machine, saved to a network drive, opened on the virtual, saved to C. No matter how little or how much code is there, it crashes. So, it's not the code. It's gotta be something else. It's the usual "Microsoft Office Excel has encountered a problem and needs to close" and closes with the Send report button.
 
Ohhh.... THAT error. Application Crash. I thought you meant just a Debug type.

Hmmm... what kind of virtual machine? Hyper-V, VMWare, VirtualBox?
 
Back
Top