Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2022, 10:17 PM
brownees brownees is offline InputBox error Windows 10 InputBox error Office 2021
Novice
InputBox error
 
Join Date: May 2022
Location: Tauranga, New Zealand
Posts: 7
brownees is on a distinguished road
Default InputBox error

Why am I getting a "Command failed" error with the following macro? It doesn't like ReferenceItem:="PhotoNum"


Sub PhotoCrossReference()
'Inserts cross reference to photo number input by user

Dim PhotoNum As Integer
PhotoNum = InputBox("Insert photo number", "Photo cross-reference", "1")

'Output cross reference
Selection.InsertCrossReference ReferenceType:="Photo", ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:="PhotoNum", InsertAsHyperlink:=False, _


IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "

End Sub
Reply With Quote
  #2  
Old 05-12-2022, 06:43 PM
brownees brownees is offline InputBox error Windows 10 InputBox error Office 2021
Novice
InputBox error
 
Join Date: May 2022
Location: Tauranga, New Zealand
Posts: 7
brownees is on a distinguished road
Red face

Solved - obviously PhotoNum shouldn't be in quotes haha. Feck how much time did I waste on that LOL
Reply With Quote
  #3  
Old 05-12-2022, 07:14 PM
brownees brownees is offline InputBox error Windows 10 InputBox error Office 2021
Novice
InputBox error
 
Join Date: May 2022
Location: Tauranga, New Zealand
Posts: 7
brownees is on a distinguished road
Default

OK next question. The following macro outputs a cross-reference to Photo 14 as per the attached which works nicely and updates when additional photos are inserted. Good start.

I want to insert a reference to just the photo number (not the label and number), i.e. output "Refer 13". Number only is not an option on the attached diaogue cross-reference box. Does that mean it can't be done?

As an aside it would be useful to see a list of all the available ReferenceKind options - is this possible?

All assistance much appreciated...


Sub TestPhotoCrossReference()
'Inserts cross reference to photo number

'Output cross reference
Selection.TypeText Text:="Refer "
Selection.InsertCrossReference ReferenceType:="Photo", ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:="14", InsertAsHyperlink:=False

Selection.TypeParagraph

End Sub
Attached Images
File Type: png zz3.png (1.3 KB, 12 views)
File Type: png zz2.png (24.5 KB, 12 views)
Reply With Quote
  #4  
Old 05-12-2022, 07:56 PM
Guessed's Avatar
Guessed Guessed is offline InputBox error Windows 10 InputBox error Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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 way that Cross References actually work is that they require a bookmarked range first and then the crossRef is simply a field that points at that bookmarked range.

The Insert Cross Reference dialog doesn't provide an option to link to just the number but if you add a bookmark around that number then you can use that Insert Cross Reference dialog to refer to the bookmark.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 05-12-2022, 08:39 PM
brownees brownees is offline InputBox error Windows 10 InputBox error Office 2021
Novice
InputBox error
 
Join Date: May 2022
Location: Tauranga, New Zealand
Posts: 7
brownees is on a distinguished road
Default Bookmark cross-referencing

Thanks Andrew. I bookmarked the "14" part of the photo caption, named it "Photo14" and successfully cross-referenced it. It looks straightforward to automate that process when the photo captions are created.

I inserted another photo earlier in the sequence and previewed the document, now the "14" in the photo caption is "15" but the bookmark is still "Photo14". That will cause me problems down the track when lots of photos are inserted because I won't know which bookmark to cross-reference to. Can you see a way around that?

Also, is it possible to output a list of all the available ReferenceKind options?

Thanks for your help.

Last edited by brownees; 05-12-2022 at 08:57 PM. Reason: Added title to post
Reply With Quote
  #6  
Old 05-12-2022, 08:56 PM
brownees brownees is offline InputBox error Windows 10 InputBox error Office 2021
Novice
InputBox error
 
Join Date: May 2022
Location: Tauranga, New Zealand
Posts: 7
brownees is on a distinguished road
Default Caption bubble text

Another question. How do I get the text to paste inside the caption bubble?

Sub TestCreateCaptionBubble()
'Pastes a caption bubble and inserts reference to a photo number

Application.Templates( _
"C:\Users\Philip Browne\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Building Blocks.dotx" _
).BuildingBlockEntries("3").Insert Where:=Selection.Range, RichText:=True

Selection.Text = "Refer photo xx"

End Sub
Attached Images
File Type: png zz2.png (24.5 KB, 11 views)
Reply With Quote
  #7  
Old 05-13-2022, 11:14 PM
Guessed's Avatar
Guessed Guessed is offline InputBox error Windows 10 InputBox error Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
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

Naming the bookmarks with the current number is not a great idea so you could use three alternatives:
1. Generate a random string like Microsoft do
2. Generate a DateHourMinSecond string which starts with a letter (bookmarks can't start with a number)
3. Use the caption words in some way eg. SEaspect, NEaspect

Putting text into the callout balloon works like this
Code:
Sub TestCreateCaptionBubble()
  'Pastes a caption bubble and inserts reference to a photo number
  Dim aRng As Range, sTmp As String, aShp As Shape
  sTmp = "C:\Users\Philip Browne\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Building Blocks.dotx"
  Set aRng = Application.Templates(sTmp).BuildingBlockEntries("3").Insert(Where:=Selection.Range, RichText:=True)
  Debug.Print aRng.ShapeRange.Count
  Set aShp = aRng.ShapeRange(1)
  aShp.TextFrame.TextRange.Text = "Refer photo xx"
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
vba inputbox method problems jmcsa3 Excel Programming 2 08-26-2020 09:02 AM
Macro to add terminology via inputbox ZiggyPop Word VBA 0 03-07-2017 04:06 AM
InputBox selects rows Dave T Excel Programming 5 09-05-2016 06:58 AM
VBA Macro for word with Inputbox ryanch69 Word VBA 2 12-03-2015 07:45 AM
InputBox error Idiot Proof Entry with InputBox arpirnat Word VBA 1 04-27-2015 10:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:10 PM.


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