Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old November 9th, 2017, 04:04 AM
Authorized User
Points: 125, Level: 2
Points: 125, Level: 2 Points: 125, Level: 2 Points: 125, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
Default Formatting a bookmark value


I am using a simple format expression but getting an error. I am copying both my code and the error I am getting is against format expression used:

UpdateBookmark "BLGrossMtons", Format(SOD.Range("rngBLGrossMtons").value, "#,###0.000")

I have copied whole code just in case if you want to know what is being done as a whole but the error is appearing against above line of code only. Note that without using the format function, my code works just fine.

Public WordApp As Object
Public WordDoc As Object
Public strBMName As String
Public objBMRange As Object

Sub ICallBookMark()
Dim SOD  As Worksheet
Set SOD = ActiveWorkbook.Worksheets(1)

Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show

If intChoice <> 0 Then
strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
End If

Set WordApp = CreateObject("word.Application")
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open(strPath, ReadOnly = False)

'On Error Resume Next

UpdateBookmark "BLGrossMtons", Format(SOD.Range("rngBLGrossMtons").value, "#,###0.000")
UpdateBookmark "BLGrossLtons", SOD.Range("rngBLGrossLtons").value
UpdateBookmark "BLGrossBbls", SOD.Range("rngBLGrossBbls").value
UpdateBookmark "Ship_tanks", SOD.Range("Ship_tanks").value

End Sub

Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
        If WordDoc.Bookmarks.Exists(BookmarkToUpdate) Then
            strBMName = BookmarkToUpdate
            Set objBMRange = WordDoc.Bookmarks(strBMName).Range
            objBMRange.Text = TextToUse
            WordDoc.Bookmarks.Add Name:=strBMName, Range:=objBMRange
            Set objBMRange = Nothing
            MsgBox "Missing data"
        End If
 End Sub
I get this error:
Method 'Range' of object'_Worksheet' failed
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Bookmark and RecordsetClone poolmd BOOK: Access 2010 VBA Programmer's Reference 5 April 8th, 2013 11:49 AM
Bookmark problem ybg1 Access VBA 3 November 16th, 2011 04:12 PM
Automate bookmark creation hogg Word VBA 1 November 12th, 2008 04:35 AM
Me.Bookmark = Me.RecordsetClone.Bookmark rkellogg Access VBA 5 September 8th, 2006 07:28 AM
Bookmark Style Terry Joseph Migliorino CSS Cascading Style Sheets 2 February 10th, 2006 07:52 AM

All times are GMT -4. The time now is 05:13 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.