Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 9th, 2017, 04:04 AM
Authorized User
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

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 10: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 06:28 AM
Bookmark Style Terry Joseph Migliorino CSS Cascading Style Sheets 2 February 10th, 2006 07:52 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.