|
-
Jun 13th, 2006, 03:11 AM
#1
Thread Starter
New Member
[RESOLVED] Word Macro - replace hard returns
Hi,
I'm new to VB but am writing a macro which is adding xml tags around Word content.
I need to change a hard return with the text <lineBreak/>, but get an error each time.
I have tried to search for "^|", and have also tried to search for Chr(10), but nothing seems to work. Am I using the wrong code to detect the shift-enter key combination?
If I change the search to "^p" or Chr(13) it works fine.
Many thanks
pramenjatjek
-
Jun 13th, 2006, 06:58 AM
#2
Re: Word Macro - replace hard returns
Welcome to the Forums.
"^p" or "Chr(13) & Chr(10)" is the solution. Did you need more help with this?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 07:53 PM
#3
Thread Starter
New Member
Re: Word Macro - replace hard returns
Thank you... and yes please 
I tried the combination of Chr(13) & Chr(10), but it still doesn't work. This is the sub
With ActiveDocument.Content.Find
.ClearFormatting
.Text = Chr(13) & Chr(10)
With .Replacement
.ClearFormatting
.Text = "<lineBreak/>"
End With
.Execute Replace:=wdReplaceAll, Format:=True
End With
Thanks again,
Pramenjatjek
-
Jun 13th, 2006, 07:56 PM
#4
Re: Word Macro - replace hard returns
Ok, so what do you mean by "doesnt work"?
What is the error message?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 09:38 PM
#5
Thread Starter
New Member
Re: Word Macro - replace hard returns
What I expected to happen was for the linebreak arrow (left pointy arrow) to be replaced with the word <lineBreak/>. But instead, nothing happens. It runs, but it appears to ignore it altogether.
When I did a search in the Word doc itself for the left pointy arrow to see that it can be detected, the code that it searches for is ^|. When I put that in the .Text line, it gives the error "Run-time error '5625'; and a little box.
Hopefully this explanation helps?
Pramenjatjek
-
Jun 13th, 2006, 09:46 PM
#6
Re: Word Macro - replace hard returns
Do you mean this character --> ¶
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 10:30 PM
#7
Thread Starter
New Member
Re: Word Macro - replace hard returns
No, the other one which leaves no space between 2 lines. It looks like a left-pointing arrow with a vertical hook at the right-side of the arrow.
Same function as <br> in html....
-
Jun 13th, 2006, 10:43 PM
#8
Re: Word Macro - replace hard returns
That sounds like the Enter key but I dont see it in word 2003. Which version are you running?
An Enter key is actually the chr(13) and Chr(10) char combination.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 11:04 PM
#9
Thread Starter
New Member
Re: Word Macro - replace hard returns
It's Word 2003, and the VB version is Microsoft Visual Basic 6.3.
It's the combination of the shift + enter key that I'm trying to capture.
-
Jun 13th, 2006, 11:44 PM
#10
Re: Word Macro - replace hard returns
Ah, a Text Wrapping Break is what its called. sorry, just really tired tonight (trying to recover from a cold).
There has to be a short cut equilivalent for it just like the paragraph "^p". I'll see what I can find.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 13th, 2006, 11:59 PM
#11
Thread Starter
New Member
Re: Word Macro - replace hard returns
Thanks so much and get well soon.
-
Jun 19th, 2006, 12:44 AM
#12
Thread Starter
New Member
Re: [RESOLVED] Word Macro - replace hard returns
This is the one that did the trick 
With ActiveDocument.Content.Find
.ClearFormatting
.Text = ChrW(11)
With .Replacement
.ClearFormatting
.Text = "<lineBreak/>"
.Font.Color = wdColorGray40
End With
.Execute Replace:=wdReplaceAll, Format:=True, MatchCase:=True, MatchWholeWord:=True
End With
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|