Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macros terminate early

I have a problem with a couple of macros I've written to
copy cells from one spreadsheet to another. The macros die
a premature death - they just stop running.

In one case, I have individual commands which select each
cell, copies it, selects the new worksheet, and then
pastes it to another specific cell. This runs for about 4-
5 cells, then stops executing, even though there are
several more operations to perform. In the other case, I'm
using a loop to copy multiple cells. It stops before it
hits the limits.

I've run both macros successfully before. Now they're
misbehaving. Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros terminate early

It would help us to answer your question if you posted your code


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Macros terminate early

Hi Pierre

The only time (but often) I encounter this is when my code has to deal with the invisible
chr(0), ascii code 0, which I believe is an "end of information" flag in many cases. The
code stops without reason and warning if that character's a part of a string or something.

If this is not the case, turn off absolutely all error handling and see if anything
happens.
--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Pierre" wrote in message
...
I have a problem with a couple of macros I've written to
copy cells from one spreadsheet to another. The macros die
a premature death - they just stop running.

In one case, I have individual commands which select each
cell, copies it, selects the new worksheet, and then
pastes it to another specific cell. This runs for about 4-
5 cells, then stops executing, even though there are
several more operations to perform. In the other case, I'm
using a loop to copy multiple cells. It stops before it
hits the limits.

I've run both macros successfully before. Now they're
misbehaving. Any ideas?



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Macros terminate early

Mudraker -

Here is a copy of the code which stops in a loop. Again,
not very elegant - more time for that later.

The purpose of this macro is to copy a field of cells from
a sheet on another machine into a specific sheet in a
Master workbook.

I'm using the VBA function for getting data from a closed
file described at J-Walk.com. The calling routine provides
the path and name of the source file.

In the first version I developed, everything works fine. I
can copy data from 5 external workbooks on the network
without a hitch. For some reason, it now process the first
file fine, then stops on the second cell of the second
file. ?????

--------------------------------------------------------
Private Sub GetSRData(filepath, filename, destsheet)
'Sub GetSRData(filepath, filename)
'Ref:

Dim Temp

s = "StatusReport"
a = "A1"

' Turn off the screen update while getting data
Application.ScreenUpdating = False

' Activate the destination worksheet
Sheets(destsheet).Activate

' Get initial cells of the target worksheet through
GetValue
' Error check for no file
If Dir(filepath & filename) = "" Then
Cells(1, 2) = "File Not Found"
Exit Sub
End If

' Error check for incompatible revision
Mstr_Rev = ThisWorkbook.Worksheets("Main").Range("A23")
a = Cells(1, 1).Address
SR_Rev = GetValue(filepath, filename, s, a)
If Mstr_Rev < SR_Rev Then
Cells(1, 2) = "File Incompatible - Rev Error"
Exit Sub
End If

' Get Name and W/E date - for Rev. 2.0
a = Cells(1, 2).Address
Cells(1, 2) = GetValue(filepath, filename, s, a)
a = Cells(1, 4).Address
Cells(1, 4) = GetValue(filepath, filename, s, a)


' Get remainder of cells
For r = 3 To 53
For c = 1 To 8
a = Cells(r, c).Address
Cells(r, c) = GetValue(filepath, filename, s,
a)
If Cells(r, c) = "0" Then Cells(r, c) = ""
Next c
Next r

' Turn the screen update back on
Application.ScreenUpdating = True

End Sub
---------------------------------------------------------
Private Function GetValue(path, file, sheet, ref)
'Ref: J-Walk "VBA Function to Get a Value From a Closed
File"
'This function operates as a Excel4 (XLM) macro to get
data from a
'closed workbook. It accesses a single cell at a time, as
follows:
' path = path to target file
' file = name of target file
' sheet = name of target sheet
' ref = target cell

'If the file is not found, "File Not Found" is returned as
the cell value.
'It is up to the calling routine to handle this case;
otherwise, all the
'cells will have "File Not Found" in them.

Dim arg As String

' Make sure the file exists
' Add "\" to end of path if not there already
If Right(path, 1) < "\" Then path = path & "\"

' Dir returns "" if no file found; bail out of routine
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If

' Create the argument for the Excel 4 macro
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)

' Execute the GetValue XLM macro
GetValue = ExecuteExcel4Macro(arg)

End Function



-----Original Message-----
It would help us to answer your question if you posted

your code


---
Message posted from http://www.ExcelForum.com/

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macros terminate early

Pierre

As your script process the first book ok and only errors after startin
on the 2nd book It sounds like their is a problem in the 2nd book.

Have you tried removing that book out of the process to see if it wil
continue with the other books

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macros terminate early

Yes - I changed the flow to skip a book. It terminated at
the same place in the new second book. I tried changing
the data in the cell where it stops (it's just text) with
no effect.

-----Original Message-----
Pierre

As your script process the first book ok and only errors

after starting
on the 2nd book It sounds like their is a problem in the

2nd book.

Have you tried removing that book out of the process to

see if it will
continue with the other books.


---
Message posted from http://www.ExcelForum.com/

.

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
excel does not terminate requested task with available resources Mukesh Patel Excel Discussion (Misc queries) 0 February 17th 06 03:17 PM
terminate a form tkaplan Excel Discussion (Misc queries) 5 October 24th 05 01:14 PM
How to terminate a condition (IF) at its first occurance? Steve Lim Excel Programming 2 October 7th 03 03:11 PM
How can you wait for the SHELL command to terminate ? Dave Peterson[_3_] Excel Programming 1 October 1st 03 09:10 AM
Can't terminate the excel instance from VB Gerhard[_2_] Excel Programming 1 July 16th 03 11:06 AM


All times are GMT +1. The time now is 06:55 PM.

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"