Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-26-2024, 01:56 AM
RRB's Avatar
RRB RRB is offline Inserting a tab char at the end of current paragraph Windows 11 Inserting a tab char at the end of current paragraph Office 2021
Susan Flamingo
Inserting a tab char at the end of current paragraph
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default Inserting a tab char at the end of current paragraph

Shouldn't this work:


With ActiveDocument.Paragraphs(1).Range
.InsertAfter vbTab
End With
It isn't doing it. I need the tab BEFORE the CRLF mark after the last regular char

Thank you and have a good day!

Susan Flamingo
Reply With Quote
  #2  
Old 02-26-2024, 02:53 AM
gmaxey gmaxey is offline Inserting a tab char at the end of current paragraph Windows 10 Inserting a tab char at the end of current paragraph Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

That is working to do what you told it to do "Insert a tab after the the last character in paragraph 1. If you want it at the end of the "current" paragraph then you can use:


Code:
Sub ScratchMacro()
  'A basic Word Macro coded by Gregory K. Maxey
  Selection.Paragraphs(1).Range.InsertAfter vbTab
lbl_Exit:
  Exit Sub
End Sub

By the way, you don't ever have to use:
"With Active Document
...
End With


Especially when you are only doing one thing. Simply use:
ActiveDocument.Paragraphs(1).Range.InsertAfter vbTab
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 02-26-2024, 03:15 AM
RRB's Avatar
RRB RRB is offline Inserting a tab char at the end of current paragraph Windows 11 Inserting a tab char at the end of current paragraph Office 2021
Susan Flamingo
Inserting a tab char at the end of current paragraph
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default

As usual works perfectly. Thank you!
Reply With Quote
  #4  
Old 03-14-2024, 10:04 AM
RRB's Avatar
RRB RRB is offline Inserting a tab char at the end of current paragraph Windows 11 Inserting a tab char at the end of current paragraph Office 2021
Susan Flamingo
Inserting a tab char at the end of current paragraph
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default

For some strange reason, it stopped working and is inserting the tab AFTER the end of the paragraph mark and not immediately BEFORE it.
What is going wrong?
Reply With Quote
  #5  
Old 03-14-2024, 01:38 PM
gmaxey gmaxey is offline Inserting a tab char at the end of current paragraph Windows 10 Inserting a tab char at the end of current paragraph Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You can try:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oRng As Range
Set oRng = Selection.Paragraphs(1).Range
If oRng.Characters.Last = Chr(13) Then
oRng.End = oRng.End - 1
End If
oRng.InsertAfter vbTab
lbl_Exit:
Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 03-14-2024, 01:49 PM
RRB's Avatar
RRB RRB is offline Inserting a tab char at the end of current paragraph Windows 11 Inserting a tab char at the end of current paragraph Office 2021
Susan Flamingo
Inserting a tab char at the end of current paragraph
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 263
RRB is on a distinguished road
Default

Yes that seems to be the winner! Thank You!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete the current paragraph by just one click without selecting it RobertDany Word VBA 2 10-10-2021 09:55 PM
Inserting text from a Userform into a Field in a paragraph in a paragraph in a word document storemaz Word VBA 1 03-13-2020 08:11 AM
syntax for inserting blank line before inserting table and after a line or paragraph SamDsouza Word VBA 8 08-04-2019 11:10 PM
inserting an image at current position stewarto Word VBA 7 03-21-2017 02:37 PM
A macro that moves the current paragraph up or down? New Daddy Word VBA 2 04-13-2014 02:25 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:50 AM.


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