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

In Word, how to prevent the cursor from moving before Paste 1

Status
Not open for further replies.

Jtorres13

Technical User
Nov 11, 2006
162
US
I have an existing macro that goes to the footer, selects All and Cuts, closes the footer and then should go back to where the cursor was before opening the cursor to paste there.

Right now is doing the cut but when it closes the Footer with:
WordBasic.closeviewheaderfooter

it's going to the top of the document.

I want it to paste it right where the cursor was before getting in the footer, no matter where it was, but the darn thing always jumps to the begining of the document like a Ctrl+Home.

Is there a way to say "go back where the cursor was" like crate a bookmar before going to the footer and then going back to the bookmark and then deleting it when I"m done.?

I need a little help with the code since I'm not very good.



 




Hi,

If you can tell me what MY code is, I'll TRY to GUESS what YOUR code is.

Maybe just posting your code would cut down on the time it might take to get you an answer.

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
True. Sorry I was fretting because of a deadline. My bad. I was able to get around it by inserting the text before cutting the existing footer.

Thanks for your prompt response.
 
Ummm, it would be better to not have anything to do with the cursor AT ALL.

You can do whatever you want in a footer with every having anything AT ALL to do with the cursor. Without ever changing the View.
Code:
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Delete
deletes the contents of the footer without having to open it, or close it.

It just DOES it. The instruction has no bearing on the cursor location AT ALL.

faq219-2884

Gerry
My paintings and sculpture
 
Ah, great answer! I'm gonna have to try that. Thanks. I got it working already, so I can't promise prompt feedback. But, thanks.
 
fumei, I tried your suggestion and it worked like a charm. I was able to go in and out the footers and it was easy to use. Thanks!
 
Just to repeat, you can perform any action inside a header or footer without EVER actually opening it, without ever using Selection. Insert text, delete text, update text, insert AutoText....whatever. Headers and footers are fully exposed within the Object Model.

One caveat though...you need to actually understand that object model to use it effectively. At least if your headers or footers are more than the simple one header for the entire document.

Headers and footers have some aspects that are not exactly intuitive. For example, there is NO odd page header or footer - even if you set the document to have different odd and even page headers and footers. There is an EvenPage header object, but no Odd one.

But then, other parts of the Word object model are kind of....kind of....hmmmmm....odd as well.

[rofl]

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top