PDA

View Full Version : Walk through Objects?



sheas33
09-21-2010, 02:40 AM
Hello,

I'm new to this forum and to Vba, I usually record macros to lighten up my job but when I tried to do the same with word run-time errors started to pop up!

I have to go through some objects within a word document (which are excel tables), and open and close them as long as I select them. (then a program within the tables does another work)
but I tried to record and I cant deselect a table once opened...
or i cant select a second table...

my code is
Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
Selection.GoTo What:=wdGoToObject, Which:=wdGoToNext, Count:=1, Name:= _
"Excel.Sheet.8"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
Selection.GoTo What:=wdGoToObject, Which:=wdGoToNext, Count:=1, Name:= _
"Excel.Sheet.8"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

I found a way to close the selection, but i cannot open a second table, run-time error 5941 appears
Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
ActiveWindow.SplitVertical = 55
ActiveWindow.SplitVertical = 100
Selection.GoTo What:=wdGoToObject, Which:=wdGoToNext, Count:=1, Name:= _
"Excel.Sheet.8"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary
ActiveWindow.SplitVertical = 30
ActiveWindow.SplitVertical = 100
Selection.GoTo What:=wdGoToObject, Which:=wdGoToNext, Count:=1, Name:= _
"Excel.Sheet.8"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=wdOLEVerbPrimary

What can I do?

fumei
09-21-2010, 09:10 AM
I am a bit confused as to what you are doing exactly. Forget the code for the moment. Please describe the steps you doing.

sheas33
09-23-2010, 02:10 AM
Sorry, I wasn't clear.

I have a Word document with several excel tables in it. I want to go to each table, select it, edit it and then pass to next table.

It doesn't have a meaning on its own but i created a macro within each excel table that runs when they are activated (so it runs when i select and edit the excel table on Word).

Therefore, i needed a macro in Word that opens all excel tables in the document.

My first problem recording it was that I could open the first table but then I wasn't able to close it and go forward.

I avoided the issue by splitting the screen (someway it worked), so when the screen turns normal I am out of the table.
But then, after I "go to" the next table I am not able to open it!

Why cannot I simply select objects on Word?