Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-21-2024, 06:59 PM
Guessed's Avatar
Guessed Guessed is offline Read into a variable a block of Word Document Windows 10 Read into a variable a block of Word Document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
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

This should get you started. Note that your concept might miss the last entry if it doesn't end with a # (which in your sample code appears to be a start point rather than a bracketing)
Code:
Sub Macro1()
  Dim aRng As Range, sFound As String
  
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "#*#"
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWholeWord = False
    .MatchWildcards = True
    Do While .Execute = True
      aRng.MoveStart Unit:=wdCharacter, Count:=1
      aRng.MoveEnd Unit:=wdCharacter, Count:=-2
      If Len(aRng.Text) > 32766 Then
        Debug.Print "Oversize Block starting: " & aRng.Paragraphs(1).Range.Text
      Else
        'Do something with the found content
        MsgBox aRng.Text
      End If
      aRng.Collapse Direction:=wdCollapseEnd
      If aRng.End = ActiveDocument.Range.End Then
        Exit Do
      Else
        aRng.End = ActiveDocument.Range.End
        aRng.Select
      End If
    Loop
  End With
End Sub

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 08-21-2024, 07:04 PM
mdlewis mdlewis is offline Read into a variable a block of Word Document Windows 7 64bit Read into a variable a block of Word Document Office 2010
Novice
Read into a variable a block of Word Document
 
Join Date: Jan 2019
Posts: 11
mdlewis is on a distinguished road
Default Thanks, I'll try it.

That looks great.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read into a variable a block of Word Document error 91 object variable or with block variable not set ubrielbryne Word VBA 1 02-25-2019 11:15 AM
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
Read into a variable a block of Word Document Run-time error 91 object variable or with block variable not set JUST ME Word VBA 4 03-25-2014 06:56 AM
Read into a variable a block of Word Document object variable or with block variable not set MJP143 Excel 1 02-11-2013 05:07 AM
Read into a variable a block of Word Document Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM

Other Forums: Access Forums

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