Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-02-2021, 04:41 PM
Guessed's Avatar
Guessed Guessed is offline PLEASE HELP: Run-time error '5941', The requested member of the collection does not exist Windows 10 PLEASE HELP: Run-time error '5941', The requested member of the collection does not exist Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

The bookmark must be there otherwise it wouldn't be in the loop, however the bookmark may not include a table cell so you should avoid that complication and just write to the bookmarked range instead. Note that doing this deletes the bookmark so you need to re-add it at the end (like you do).

Is the RangeValue function looking Word or Excel? I presume it must be in Excel and it is not clear that the function tests whether the named range exists in Excel so that could fail if that is the case.
Code:
Dim aRng as Range
For a = wDoc.Bookmarks.Count To 1 Step -1
  Set item = wDoc.Bookmarks(a)
  itemName = item.Name
  aRng = item.Range
  fValue = RangeValue(itemName)
  If IsNumeric(fValue) Then
     Select Case formatCell
         Case "Percentage", "0%", "0.0%", "0.00%", "0.00""x"""
             aRng.Text = Format(fValue, formatCell)
         Case Else
             aRng.Text = Format(fValue, "#,##0;(#,##0);"" - """)
     End Select
  Else
     aRng.Text = fValue
  End If
  wDoc.Bookmarks.Add itemName, aRng 
Next a
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
runtime error 5941



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word template with Macro keeps getting an error ''Run-time error 5941'' Marcel Word VBA 3 12-17-2019 04:55 PM
PLEASE HELP: Run-time error '5941', The requested member of the collection does not exist Word 2010 the requested member of the collection does not exist flyboy3300 Word VBA 15 08-02-2016 01:40 AM
Presentation (unknown member) : Object does not exist. Benazeer PowerPoint 0 03-08-2016 06:28 AM
Run-time error 5941 when deleting a row from a table jpb103 Word VBA 1 05-26-2014 07:08 AM
5941 requested member of collection does not exist Prevents Userform from Showing marksm33 Word VBA 1 02-22-2014 08:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:49 PM.


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