Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2016, 10:02 AM
mrsjetset mrsjetset is offline Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Windows 10 Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Office 2016
Novice
Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work
 
Join Date: Jun 2016
Posts: 5
mrsjetset is on a distinguished road
Question Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work


I have several bookmarks and cross-references to fill in from a userform, and finally have gotten the basic code to work (first solution found here: http://www.word.mvps.org/FAQs/Macros...AtBookmark.htm). However, I have not a huge number, but enough I'd like to be able to get the subroutine to work. I have put it in several places in the userform code, but I keep getting a 5441 error: The requested member of the collection does not exist. As a side note, the very first time I inserted it (absolutely last thing in the code) it did work (I called it only once in the cmdOK_Click subroutine). When I called it more times for more bookmarks, I got this error. Assistance is greatly appreciated!
Reply With Quote
  #2  
Old 06-27-2016, 06:09 PM
Guessed's Avatar
Guessed Guessed is offline Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Windows 10 Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

That code is most likely not your problem. You will need to post your template so the whole code can be examined. Anything that deletes, cuts or replaces a range could be responsible for removing your bookmarks.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 06-28-2016, 06:11 AM
mrsjetset mrsjetset is offline Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Windows 10 Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Office 2016
Novice
Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work
 
Join Date: Jun 2016
Posts: 5
mrsjetset is on a distinguished road
Default

I think the code has to be the issue seeing as how I didn't edit the document or the form, only the code. And since the original solution works when used over and over but the subroutine produces an error code, I don't see how it can not be the code. I will just continue to use the original solution en masse I suppose.
Reply With Quote
  #4  
Old 06-28-2016, 07:05 PM
Guessed's Avatar
Guessed Guessed is offline Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Windows 10 Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You haven't specified where the code is failing. However if the function is throwing an error like that then there are only two possibilities:
1. There is no activedocument.
2. You are passing a bookmark name that doesn't exist in the activedocument.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 06-29-2016, 10:03 AM
mrsjetset mrsjetset is offline Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Windows 10 Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Office 2016
Novice
Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work
 
Join Date: Jun 2016
Posts: 5
mrsjetset is on a distinguished road
Default

Alright, got that situation all worked out. I think I was using an incorrect copy of the document where the bookmark had been replaced and not re-added (operator error) because I re-added the subroutine and set it up for all the bookmarks, and everything is hunky-dory with that part now.

The bigger issue that I have left is that the userform doesn't Unload on cmdClick_OK, even though I have Unload Me as the last line before the end of the subroutine. I click the X and it goes away, but I'd like for the OK click to populate the document and close the form. I think it's possible, but I'm not 100% sure. If I have to add in a Close button it's not the end of the world, but from everything I've read it seems Unload Me should work. Can't seem to find a good reference for Word VBA that's current.

Next issue is the cross-references keep the format of the original bookmark. I thought I read somewhere that there was a way to tell them to keep their own formatting and use just the value of the bookmark, but I have searched again and cannot seem to find what the solution to that was, nor have I been able to recall it.

A third, much more minor issue, is that my userform is "multipage" and I can't figure out how to set it up so it always shows the first page first. Seems that whichever page I'm on when I save it is the one the userform opens on. This is, however, a very minor issue, and I don't anticipate a lot of changes once the form is in use so it's not a big deal, I just wondered if there was a property I needed to change the value of.

If I need to post the code or the file I'm happy to do so, as long as the forum will agree with me today.
Reply With Quote
  #6  
Old 06-29-2016, 05:06 PM
Guessed's Avatar
Guessed Guessed is offline Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Windows 10 Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

If the userform is remembering the multipage you were on then it is because it remained loaded in memory. I usually place the "Unload userformname" line in the same Sub that displays the userform - not in the userform module itself. You can use a Me.Hide command to allow that sub to proceed. If the form is unloaded then it will default to the initial multi-page next time the userform is summoned.

I have no idea if the "forum will agree with you today" but if you don't post your code we can't tell you why it doesn't work. The only code you have shown us so far isn't dealing with cross-references but it is replacing a bookmarked range with a string and then wrapping that in a bookmark - this will ALWAYS result in formatting that looks the same as the previous text since no formatting is contained in a string.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work How to make a SEQ field show up in cross references? Roscoe Word 5 06-01-2016 01:39 PM
Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Outlook 2013 - How to make "deleted" items to to the DELETED folder? drgerry Outlook 3 05-16-2016 05:18 AM
Convert manual cross references in footnotes to other footnotes to automatic cross references ghumdinger Word VBA 7 11-20-2014 11:47 PM
Where to put Subroutine to make sure bookmarks aren't deleted so cross-references work Bookmarks & cross-references Suchoklates Word 1 09-19-2013 02:32 AM
Bookmarks with different figure references Dan_68 Word 0 02-15-2010 08:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft