Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2022, 10:45 PM
soroush.kalantari soroush.kalantari is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Competent Performer
How to Write a macro to automate Cross Refrenceing?
 
Join Date: Jun 2021
Posts: 124
soroush.kalantari is on a distinguished road
Default How to Write a macro to automate Cross Refrenceing?

As following, I have written a macro to automate Cross Referencing to Word Curves. When I running the macro, It encounter “Run-time error 4198,. Command failed”, Can anybody Guides me on this issue? (When I first wrote this macro, It worked for a While, But then stopped working)

Sub crosscurve()
Selection.InsertCrossReference ReferenceType:="curve", ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:=InputBox("what is the number of curve do you want to refer?"), InsertAsHyperlink:=True, _

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


End Sub

Last edited by soroush.kalantari; 04-18-2022 at 04:24 AM.
Reply With Quote
  #2  
Old 04-18-2022, 03:34 AM
macropod's Avatar
macropod macropod is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Multiple issues:
1. There is no such thing as a "curve" Reference Type. See:
Selection.InsertCrossReference method (Word) | Microsoft Docs
WdReferenceType Enum (Microsoft.Office.Interop.Word) | Microsoft Docs
WdCaptionLabelID Enum (Microsoft.Office.Interop.Word) | Microsoft Docs
2. You're missing the required quite characters & line continuation characters here:
Code:
number of curve " & _
"do you
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-18-2022, 04:28 AM
soroush.kalantari soroush.kalantari is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Competent Performer
How to Write a macro to automate Cross Refrenceing?
 
Join Date: Jun 2021
Posts: 124
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Multiple issues:
1. There is no such thing as a "curve" Reference Type. See:
Selection.InsertCrossReference method (Word) | Microsoft Docs
WdReferenceType Enum (Microsoft.Office.Interop.Word) | Microsoft Docs
WdCaptionLabelID Enum (Microsoft.Office.Interop.Word) | Microsoft Docs
2. You're missing the required quite characters & line continuation characters here:
Code:
number of curve " & _
"do you
Thank you for your reply. I have created a caption label for my Word curves and Now I want to cross-reference them(curve is label name). I don’t think there be a issue in this process (when I cross reference manually it works. Also as I told in question, even the macro worked for a while, but then stopped working.) The 2th issue ( Line continuation character)doesn't exists in my code. (I had pasted my code in the site in the wrong way, and Now I corrected it)
Reply With Quote
  #4  
Old 04-18-2022, 07:19 PM
Guessed's Avatar
Guessed Guessed is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
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

Your code works on my machine although I did change it to separate the inputbox out
Code:
Sub crosscurve()
  Dim str As String
  str = InputBox("what is the number of curve do you want to refer?")
  Selection.InsertCrossReference ReferenceType:="curve", ReferenceKind:=wdOnlyLabelAndNumber, _
      ReferenceItem:=str, InsertAsHyperlink:=True, _
      IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
End Sub
The things I would expect would cause it to fail are:
1. The existence of a 'Curve' caption is at the application level. The presence of some curve instances in a document brought from another machine is not enough to tell Word that the type exists. Have you inserted at least one Curve caption on that machine?
2. Is it sensitive to capitalisation?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-18-2022, 08:35 PM
soroush.kalantari soroush.kalantari is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Competent Performer
How to Write a macro to automate Cross Refrenceing?
 
Join Date: Jun 2021
Posts: 124
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Your code works on my machine although I did change it to separate the inputbox out
Code:
Sub crosscurve()
  Dim str As String
  str = InputBox("what is the number of curve do you want to refer?")
  Selection.InsertCrossReference ReferenceType:="curve", ReferenceKind:=wdOnlyLabelAndNumber, _
      ReferenceItem:=str, InsertAsHyperlink:=True, _
      IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
End Sub
The things I would expect would cause it to fail are:
1. The existence of a 'Curve' caption is at the application level. The presence of some curve instances in a document brought from another machine is not enough to tell Word that the type exists. Have you inserted at least one Curve caption on that machine?
2. Is it sensitive to capitalisation?
Thank you for your reply. I have found the issue. This code fails because when I insert a caption for my Word curves, sometimes unexpectedly a textbox which is without border and outline and color encompasses the captions. If I solve this problem, I can cross -reference my word curves with this code again.
Reply With Quote
  #6  
Old 04-18-2022, 09:37 PM
Guessed's Avatar
Guessed Guessed is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
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

Ahh, that would likely be caused when you add a caption to a floating (text wrapped) object rather than an inline one.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 04-19-2022, 07:40 PM
soroush.kalantari soroush.kalantari is offline How to Write a macro to automate Cross Refrenceing? Windows 10 How to Write a macro to automate Cross Refrenceing? Office 2016
Competent Performer
How to Write a macro to automate Cross Refrenceing?
 
Join Date: Jun 2021
Posts: 124
soroush.kalantari is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Ahh, that would likely be caused when you add a caption to a floating (text wrapped) object rather than an inline one.
Ok. I got the point. Thank you very much.
Reply With Quote
Reply

Tags
cross referencing

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Write a macro to automate Cross Refrenceing? Can I write a macro in which I Use the Mouse? Rayroshi Word VBA 4 09-06-2020 06:28 PM
How to write macro yoyo4 Excel Programming 1 11-19-2017 11:43 PM
Macro: automate a contract? 1questionman Word VBA 3 10-17-2017 08:29 PM
Macro to automate changes to slide Mearsy PowerPoint 0 08-18-2015 03:29 AM
How to Write a macro to automate Cross Refrenceing? Can I automate or make a macro for this? mkoenig Word VBA 1 01-31-2010 02:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:21 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