Mutiple Excel-Vb Questions

Mutiple Excel-Vb Questions

Anonymous
Not applicable
245 Views
1 Reply
Message 1 of 2

Mutiple Excel-Vb Questions

Anonymous
Not applicable
I'm somewhat new to this and really strugglying linking to excel. I simply need my application to link itself to an existing excel file by its filepath upon opening(application), so that I can then use data from the application and put it into the spreadsheet. Also is there a command to reset an excel spreadsheet to its saved self so that it can be used as somewhat of an erase command? Is there anywhere I can get examples of this kind of coding so that i can try and apply it to what i'm doing?
0 Likes
246 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
There should be numerous examples of connecting to Excel in this group. Try
searching for "excel", "GetObject" or "CreateObject". I believe there is
also a special group for connectivity.

According to Excel help, you can not use the "Undo" method to reverse any
changes made through code.

I think your only option to revert to the "last saved" state (without a
workaround) will be to close and reopen the file.

Here is a sample workaround (hack) that will create a hidden "undo"
worksheet. It will copy everything from the first worksheet to the hidden
worksheet. You could run it in reverse to simulate an undo. I did not try
using "xlSheetVeryHidden". The docs say that would prevent users from ever
unhiding the sheet.

Dim oUndoSheet As Worksheet
Dim oDataSheet As Worksheet

On Error Resume Next

Set oUndoSheet = ThisWorkbook.Worksheets("UndoData")

If Err Then
Err.Clear
Set oUndoSheet =
ThisWorkbook.Worksheets.Add(after:=Worksheets(Worksheets.Count))
oUndoSheet.Name = "UndoData"
End If

On Error GoTo 0

oUndoSheet.Visible = xlSheetHidden
oUndoSheet.UsedRange.Clear

Set oDataSheet = ThisWorkbook.Worksheets(1)

oDataSheet.UsedRange.Copy
oUndoSheet.Paste Destination:=oUndoSheet.Cells(1, 1)

oDataSheet.Activate
0 Likes