Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Code runs every other time

This code works the first time. It will give the right
answer in the msgbox 1 every other time I run it the
msgbox returns 0. If I remove the getobject call and use
only creatobject then the code runs every other time. The
code will open Excel on the second run but then hangs. I
have to close Excel manually. After that, the code will
run a 3rd time but fail the fourth run.

It seems that Excel is not closing properly. I am calling
Excel from Outlook.

Any help would be greatly appreciated
Thanks in advance
Mike

public dim goodfiles()
Sub test2()
Dim goodfiles(5) As Integer
Dim xl As Object

On Error Resume Next
Set xl = GetObject("excel.application")
If Err < 0 Then
Err.Clear
Set xl = CreateObject("Excel.Application")
End If
xl.Application.Workbooks.Open _
FileName:=("c:\windows\application
data\microsoft\excel\xlstart\personal.xls")
xl.Application.Visible = True
xl.Parent.Windows(1).Visible = True
xl.Application.Workbooks.Open _
FileName:=("c:\DVW\REPORTS\finchk.xls")

goodfiles(1) = Range("a30").Value
xl.Application.ActiveWorkbook.Save
xl.Application.Quit
Set xl = Nothing

MsgBox goodfiles(1)
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code runs every other time

public dim goodfiles() as Integer

Sub test2()
ReDim Preserve goodfiles(1 to 5)
Dim xl As Object

On Error Resume Next
Set xl = GetObject("excel.application")
If Err < 0 Then
Err.Clear
Set xl = CreateObject("Excel.Application")
End If
xl.Workbooks.Open _
FileName:=("c:\windows\application
data\microsoft\excel\xlstart\personal.xls")
xl.Visible = True
xl.Windows(1).Visible = True
xl.Workbooks.Open _
FileName:=("c:\DVW\REPORTS\finchk.xls")

goodfiles(1) = xl.ActiveSheet.Range("a30").Value
xl.ActiveWorkbook.Save
xl.Quit
Set xl = Nothing

MsgBox goodfiles(1)
End Sub

xl is the application object.

qualifying Range("a30") should clear up your problem.

--
Regards,
Tom Ogilvy


Mike Waldron wrote in message
...
This code works the first time. It will give the right
answer in the msgbox 1 every other time I run it the
msgbox returns 0. If I remove the getobject call and use
only creatobject then the code runs every other time. The
code will open Excel on the second run but then hangs. I
have to close Excel manually. After that, the code will
run a 3rd time but fail the fourth run.

It seems that Excel is not closing properly. I am calling
Excel from Outlook.

Any help would be greatly appreciated
Thanks in advance
Mike

public dim goodfiles()
Sub test2()
Dim goodfiles(5) As Integer
Dim xl As Object

On Error Resume Next
Set xl = GetObject("excel.application")
If Err < 0 Then
Err.Clear
Set xl = CreateObject("Excel.Application")
End If
xl.Application.Workbooks.Open _
FileName:=("c:\windows\application
data\microsoft\excel\xlstart\personal.xls")
xl.Application.Visible = True
xl.Parent.Windows(1).Visible = True
xl.Application.Workbooks.Open _
FileName:=("c:\DVW\REPORTS\finchk.xls")

goodfiles(1) = Range("a30").Value
xl.Application.ActiveWorkbook.Save
xl.Application.Quit
Set xl = Nothing

MsgBox goodfiles(1)
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba code runs...need spaces ........ Wanna Learn Excel Discussion (Misc queries) 2 January 20th 09 12:44 PM
Can you code a macro so it runs multiple times in the same workboo dpmac Excel Discussion (Misc queries) 2 April 18th 06 07:40 PM
How to keep from going dizzy when my code runs TBA[_2_] Excel Programming 3 September 23rd 03 11:33 PM
Code that runs each time AFTER a sheet is cut off the book keks Excel Programming 1 August 22nd 03 02:01 PM
OnTime method only runs 1 time JP[_7_] Excel Programming 2 August 15th 03 09:27 AM


All times are GMT +1. The time now is 09:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"