Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force Closing Excel in Outlook

Status
Not open for further replies.

Hacktastic

Technical User
Feb 27, 2007
54
US
Hi Everybody,

I have a code that converts a CSV to a XLS within outlook. This is needed because it runs in conjunction with a rule i set up.

Everything works fine, however when i try to open the file, it refuses to open and I have to CNTL+ALT+DEL my way out of Excel just to open the file.

Something is getting stuck somewhere. Any Ideas?


Code:
Sub concsvxls()

 
Dim myolapp As Excel.Application
 
''Delete File
Dim File As String
File = "Z:\test\reportEXL.xls"
KillProperly (File)


''Create new File for SSIS Package
    Workbooks.OpenText FileName:="Z:\test\report.csv", Origin:=xlWindows, _
        StartRow:=7, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1)), _
        TrailingMinusNumbers:=True
    ActiveWorkbook.SaveAs FileName:="Z:\google\reportEXL.xls", FileFormat:= _
        xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
 
Set myolapp = Nothing

End Sub
 
[!]myolapp.[/!]Workbooks.OpenText ...
[!]myolapp.[/!]ActiveWorkbook.SaveAs ...
[!]myolapp.Quit[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,

Thanks for your help, unfortunately, this doesn't work, it wants me to either declare the variable or put it in a with block, when i do put it in a with block, myolapp.quit closes Outlook (I'm running this code out of Outlook not Excel)
 
What is your actual code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Do you have this code declaring myolapp as an Outlook.Application elsewhere?
 

Thanks for the replies,

no i do not have myolapp declared anywhere else.

here is the modified code, it saves the file, however doesn't close the background run of excel(which keeps the newly created file as read only), and closes out of Outlook.

Code:
Sub concsvxls()

 
Dim myolapp As Excel.Application


''Delete File
Dim File As String
File = "Z:\google\reportEXL.xls"
KillProperly (File)

''Create new File for SSIS Package
     myolapp.Workbooks.OpenText FileName:="Z:\google\report.csv", Origin:=xlWindows, _
        StartRow:=7, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1)), _
        TrailingMinusNumbers:=True
     myolapp.ActiveWorkbook.SaveAs FileName:="Z:\google\reportEXL.xls", FileFormat:= _
        xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
        
        
  myolapp.Quit
   
  


End Sub
 
actually....

DUR....


never set the new excel application
Code:
Dim myolapp As Excel.Application
Set myolapp = New Excel.Application
now everything works perfect

Thanks guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top