Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-03-2023, 07:46 AM
vivka vivka is offline Insert a condition in Find and Replace Windows 7 64bit Insert a condition in Find and Replace Office 2016
Expert
 
Join Date: Jul 2023
Posts: 305
vivka is on a distinguished road
Default


You are welcome, RobiNew! I've just slightly modified your code. And, really, I don't know a better code for doing this job. I think, your algorithm is quite fast and optimal. Maybe experts here, if they want, can offer a different solution. I'd like to have another good lesson!
Reply With Quote
  #2  
Old 12-03-2023, 09:48 AM
RobiNew RobiNew is offline Insert a condition in Find and Replace Windows 10 Insert a condition in Find and Replace Office 2016
Competent Performer
Insert a condition in Find and Replace
 
Join Date: Sep 2023
Posts: 231
RobiNew is on a distinguished road
Default

Well, that was just a friendly comment! Perhaps you can explain why the code here below doesn't work at all. I want to go to the first page of the document without using Selection. Thanks!
Code:
Dim myRange As Range
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseStart
Reply With Quote
  #3  
Old 12-03-2023, 02:54 PM
vivka vivka is offline Insert a condition in Find and Replace Windows 7 64bit Insert a condition in Find and Replace Office 2016
Expert
 
Join Date: Jul 2023
Posts: 305
vivka is on a distinguished road
Default

RobiNew, as for me,
selection.HomeKey wdStory
is the best way of moving the cursor to the doc's start.
If you don't like it, you can use
ActiveDocument.range(0, 0).Select
Reply With Quote
  #4  
Old 12-04-2023, 06:19 AM
gmaxey gmaxey is offline Insert a condition in Find and Replace Windows 10 Insert a condition in Find and Replace Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default It does work as it is coded.

Quote:
Originally Posted by RobiNew View Post
Well, that was just a friendly comment! Perhaps you can explain why the code here below doesn't work at all. I want to go to the first page of the document without using Selection. Thanks!
Code:
Dim myRange As Range
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseStart



RobiNew


Your code does work for what you are telling it to do. After running that code, the range is at the start of the document. Consider:
Code:
Sub ScrahtchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim myRange As Range
Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseStart
myRange.InsertBefore "I'm here."
lbl_Exit:
  Exit Sub
End Sub

If you want to start typing at the start of the document then you have to move the insert point to the start of the document as others have explained.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 12-04-2023, 07:23 AM
vivka vivka is offline Insert a condition in Find and Replace Windows 7 64bit Insert a condition in Find and Replace Office 2016
Expert
 
Join Date: Jul 2023
Posts: 305
vivka is on a distinguished road
Default

Yes, Greg, you are absolutely right! I was about to write this to RobiNew with the demonstration you used.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert a condition in Find and Replace Find & Replace to insert thousands separators jeffreybrown Word 3 10-19-2019 04:37 PM
Insert a condition in Find and Replace Find and replace condition norgro Word VBA 2 07-31-2015 06:38 AM
Insert a condition in Find and Replace Find and Replace - How to insert brackets around all numbers in a doc Natedogg Word 2 05-21-2015 07:16 AM
Insert a condition in Find and Replace Insert text at the end of a sentence Find/Replace AlmostFriday Word 6 06-17-2012 05:21 AM
Find & Replace Insert Issue mipacker Word 0 02-18-2009 08:59 AM

Other Forums: Access Forums

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