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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Excel Workbook from code

Status
Not open for further replies.

MarkMcD

Technical User
May 20, 2001
22
AU
I have an Excel Workbook that users enter data into and then press a button and the data gets processed into another application.

The processing occurs in code (one call to the other application per row) and I'd like to save the worksheet after each 100 rows have been processed. The update process often hangs and my only option is to terminate the Excel session (CTRL+ALT+DEL) without having saved where the processing was up to.

Any help/suggestions would be appreciated.

 
Hi,

If you simply want to save the workbook with it's current name then the code is:

ActiveWorkbook.Save

However what it sounds like you need to do is keep track of where your processing is up to so you can restart from that point if the system hangs.

Sub TestLoop()

SaveLimit = 5 'save after how many rows

'loop through each row in named rang 'MyRange'
For Each MyRow In ActiveSheet.Range("MyRange").Rows

'external process call here

'set value of counter cell. named cell on worksheet
ActiveSheet.Range("Counter").Value = MyRow.Row

If MyRow.Row = SaveLimit Then
SaveLimit = SaveLimit + SaveLimit
ActiveWorkbook.Save
Else
End If


Next


End Sub Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top