Run-time error "4605" "... not a table"

I am learning VBA and am using a WORD 2007 macro-enabled template to capture hours worked and accomplishments for four tasks.

I need to SUM the rows for each task and SUM the columns for each day of the week.   I do not want to have to click on the totals cell and then click "update" for all eleven totals.   I am trying to use a VBA macro to update these 11 fields when I click a command button.

 

However, when I try this, I get the error,  Run-time error.  "This method or property is not available because some or all of the object does not refer to a table."

When I click Debug the VBE shows the following instruction as the culprit -

 

Selection.MoveRight Unit:=wdCell

 

I have tried using "Count:=1"

I have tried using "Count:=1, Extend:=wdMove

 

Same error.  I am certain I am overlooking something simple. But, I may also be trying to use the commands in a manner for which they are not intended. 

I would appreciate any assistance/guidance anyone can offer.

 

Thanks,

 

Ferg

Answer
Answer
Without seeing the template itself and the segment of the macro that surrounds the line you quoted, it's impossible to say how to fix the error. In some way, that line is trying to move the Selection by one cell when the Selection isn't currently in a table at all.

However, the better path is to avoid reinventing the wheel. The UpdateAll macro in http://www.gmayor.com/installing_macro.htm will do your job, without moving the Selection at all.

An important lesson to learn early in the study of VBA is that you shouldn't always treat it as a "ghost user" that types on the keyboard and moves the mouse. Almost everything in Word is an "object" that can do actions without selecting. In Graham's macro, the line oStory.Fields.Update causes all the fields in a specific part of the document to update, without having to select the fields or say which fields should update.
_____________________________
https://jay-freedman.info

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated August 29, 2023 Views 2,478 Applies to: