Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 02-08-2022, 05:40 AM
gmayor's Avatar
gmayor gmayor is offline I am automating word using vba. Need Help replacing paragraph with variable information Windows 10 I am automating word using vba. Need Help replacing paragraph with variable information Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default


You said that in your last post. What do you want it replaced with?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #17  
Old 02-08-2022, 08:38 AM
Puneet Singh Puneet Singh is offline I am automating word using vba. Need Help replacing paragraph with variable information Windows XP I am automating word using vba. Need Help replacing paragraph with variable information Office 2010
Novice
I am automating word using vba. Need Help replacing paragraph with variable information
 
Join Date: Feb 2022
Posts: 13
Puneet Singh is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You said that in your last post. What do you want it replaced with?
With data present in excel. The same excel which we used in earlier macro. The data present in one cell that is B45
Reply With Quote
  #18  
Old 02-08-2022, 10:34 PM
gmayor's Avatar
gmayor gmayor is offline I am automating word using vba. Need Help replacing paragraph with variable information Windows 10 I am automating word using vba. Need Help replacing paragraph with variable information Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

OK The following will do that, however it will not be formatted in the same manner with each line a separate paragraph indented with spaces. It will be formatted to look the same using a pargraph format with a half inch indent.

Code:
Option Explicit

Sub ReplacePara()
Dim lPara As Long
Dim oRng As Range
Dim oCC As ContentControl
    With ActiveDocument
        For lPara = .Paragraphs.Count To 1 Step -1
            If InStr(1, .Paragraphs(lPara).Range.Text, _
                     "Nature and Necessity") > 0 Then
                Set oRng = .Paragraphs(lPara).Range
                oRng.MoveStart wdParagraph
                Exit For
            End If
        Next lPara
        For lPara = .Paragraphs.Count To 1 Step -1
            If InStr(1, .Paragraphs(lPara).Range.Text, _
                     "*****THIS IS A COMPLETE UNDERTAKING*****") > 0 Then
                oRng.End = .Paragraphs(lPara).Range.End - 1
                Exit For
            End If
        Next lPara
        oRng.Select
        oRng.ParagraphFormat.LeftIndent = InchesToPoints(0.5)
        oRng.Font.Bold = False
        oRng.Text = GetExcelB45Data
    End With
End Sub

Private Function GetExcelB45Data() As String
Dim strWorkbook As String: strWorkbook = "C:\Path\Job Aid Bay.xlsm" 'The path of the workbook
Dim xlApp As Object
Dim xlBook As Object
    On Error Resume Next
    Set xlApp = GetObject(, "Excel.Application")
    If Err Then
        Set xlApp = CreateObject("Excel.Application")
    End If
    On Error GoTo 0
    Set xlBook = xlApp.Workbooks.Open(FileName:=strWorkbook)
    xlApp.Visible = True
    GetExcelB45Data = xlBook.Sheets("MAIN").Range("B45") 'the Excel cell to copy
    xlBook.Close savechanges:=False
lbl_Exit:
    Err.Clear
    Set xlBook = Nothing
    Set xlApp = Nothing
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #19  
Old 02-08-2022, 10:48 PM
Puneet Singh Puneet Singh is offline I am automating word using vba. Need Help replacing paragraph with variable information Windows XP I am automating word using vba. Need Help replacing paragraph with variable information Office 2010
Novice
I am automating word using vba. Need Help replacing paragraph with variable information
 
Join Date: Feb 2022
Posts: 13
Puneet Singh is on a distinguished road
Default

Thanks sir...
Want to know one thing. In excel file on Main Sheet we have a dropdown list which has a multiple items when we select an item from list data on another get change now i want to copy that change data issue here is the data in another sheet is not always showing on fixed cell number. The cell number is changing on every select in dropdown. How to get this.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
I am automating word using vba. Need Help replacing paragraph with variable information Replacing random paragraph endings in text jp91306 Word 3 04-23-2019 03:32 PM
I want to create a bar chart of multiple variable. Then I need to draw trend lin of those variable shimulsiddiquee Excel 1 05-16-2017 07:39 AM
Replacing paragraph formatting before column break also changes the next paragraph after the break jjmartin1340 Word 3 09-21-2015 10:50 PM
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

Other Forums: Access Forums

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