Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2017, 10:56 AM
Gowri Gowri is offline how to replace a text in word by cell value (bulleted text) using macro Windows 8 how to replace a text in word by cell value (bulleted text) using macro Office for Mac 2011
Novice
how to replace a text in word by cell value (bulleted text) using macro
 
Join Date: Mar 2017
Posts: 4
Gowri is on a distinguished road
Default how to replace a text in word by cell value (bulleted text) using macro


I have to replace a text in word by cell value in excel using macro. Am getting output but if the cell contain bulleted text it is coming in the same line in word.I want the same cell value to be replaced in word.
Reply With Quote
  #2  
Old 03-18-2017, 09:52 PM
macropod's Avatar
macropod macropod is offline how to replace a text in word by cell value (bulleted text) using macro Windows 7 64bit how to replace a text in word by cell value (bulleted text) using macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You really haven't given us anything meaningful to work with. There is no particular reason replacing text should change paragraph formats, regardless of where the data are coming from.

There are plenty of code examples on this forum for using Excel workbooks to hold Find/Replace strings.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-18-2017, 11:40 PM
Gowri Gowri is offline how to replace a text in word by cell value (bulleted text) using macro Windows 8 how to replace a text in word by cell value (bulleted text) using macro Office for Mac 2011
Novice
how to replace a text in word by cell value (bulleted text) using macro
 
Join Date: Mar 2017
Posts: 4
Gowri is on a distinguished road
Default

Here is my code. Please check it.

Code:
Dim oWordApp As Object, oWordDoc As Object, rngStory As Object
    Dim sFolder As String, strFilePattern As String
    Dim strFileName As String, sFileName As String
 Dim i As Long, j As Long, FindWord As String, Ans As String, FoundWord As String, ReplaceAns As String
Call CopyingAFile
        Set oWordApp = CreateObject("Word.Application")
    oWordApp.Visible = True
        Set oWordDoc = oWordApp.Documents.Open("E:\Output\Original.docx")
For i = 2 To 40
            FindWord = Sheets("LookUp").Range("B" & i).Value
            If FindWord <> vbNullString Then
            FoundWord = FindWord
       Ans = Sheets("Answers").Range("C" & i).Value
       If Ans <> vbNullString Then
       ReplaceAns = Ans
        For Each rngStory In oWordDoc.StoryRanges
            With rngStory.Find
                .Text = FoundWord
                .Replacement.Text = ReplaceAns
                .Wrap = wdFindContinue
                .Execute Replace:=wdReplaceAll
            End With
        Next
        End If
End If
Next i
        oWordDoc.Close SaveChanges:=True
        MsgBox "File Saved"
    oWordApp.Quit
    MsgBox " Word File Modified"
    Set oWordApp = Nothing: Set oWordDoc = Nothing
End Sub

If i run the code the cell value in excel is ·Firstline
·Secondline
replaced in word as ·Firstline ·Seconline . But my requirement is to replace in word as ·Firstline
·Seconline

Last edited by macropod; 03-19-2017 at 12:06 AM. Reason: Added code tags to restore formatting
Reply With Quote
  #4  
Old 03-19-2017, 12:05 AM
macropod's Avatar
macropod macropod is offline how to replace a text in word by cell value (bulleted text) using macro Windows 7 64bit how to replace a text in word by cell value (bulleted text) using macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There is no reference to ·Firstline or ·Secondline in your code, so it's a bit hard to understand what you mean. That said, it appears you find text is in column B of the 'LookUp' sheet and the replace text is in column C of the 'Answers' sheet. The key to your problem would appear to be whatever the relevant cells contain - especially for the 'Answers' sheet.

We'd be able to understand the issues better if you provided both sample document and a workbook with some sample data. You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-19-2017, 12:13 AM
gmayor's Avatar
gmayor gmayor is offline how to replace a text in word by cell value (bulleted text) using macro Windows 10 how to replace a text in word by cell value (bulleted text) using macro Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

Without having the materials to test, something like the following may work, Chr(183) is the bullet character. Note that if you are using late binding to Word you need to use the numeric equivalents of the 'wd' commands (see below).

Code:
If Ans <> vbNullString Then
       ReplaceAns = Replace(Ans, Chr(32) & Chr(183), vbCr & Chr(183))
       For Each rngStory In oWordDoc.StoryRanges
              With rngStory.Find
                    .Text = FoundWord
                    .Replacement.Text = ReplaceAns
                    .Wrap = 1
                    .Execute Replace:=2
              End With
       Next
End If
__________________
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
  #6  
Old 03-19-2017, 08:57 AM
Gowri Gowri is offline how to replace a text in word by cell value (bulleted text) using macro Windows 8 how to replace a text in word by cell value (bulleted text) using macro Office for Mac 2011
Novice
how to replace a text in word by cell value (bulleted text) using macro
 
Join Date: Mar 2017
Posts: 4
Gowri is on a distinguished road
Default

I tried your code. It is also not working. In output am getting bullets but it is replacing in the same line. I want it to be replaced in next line if bullet is in cell value of excel.
Reply With Quote
  #7  
Old 03-19-2017, 09:48 PM
gmayor's Avatar
gmayor gmayor is offline how to replace a text in word by cell value (bulleted text) using macro Windows 10 how to replace a text in word by cell value (bulleted text) using macro Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

Post the document and worksheet.
__________________
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
  #8  
Old 03-19-2017, 11:17 PM
Gowri Gowri is offline how to replace a text in word by cell value (bulleted text) using macro Windows 8 how to replace a text in word by cell value (bulleted text) using macro Office for Mac 2011
Novice
how to replace a text in word by cell value (bulleted text) using macro
 
Join Date: Mar 2017
Posts: 4
Gowri is on a distinguished road
Default

i have attached my files. I want it to be replaced as ·C
·C++
·Java
Attached Files
File Type: xlsm sample.xlsm (32.6 KB, 14 views)
File Type: docx Doc1.docx (11.3 KB, 9 views)
Reply With Quote
  #9  
Old 03-26-2017, 04:14 AM
macropod's Avatar
macropod macropod is offline how to replace a text in word by cell value (bulleted text) using macro Windows 7 64bit how to replace a text in word by cell value (bulleted text) using macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your workbook structure doesn't exactly make it easy to extract the data. For example you don't have either a row or column titled 'college name', to match your entry in the Word file; all you have is 'College name' (note the difference in case) embedded in another string. It's also not apparent why you've set a loop to process rows 2 To 40 when your data only span 4 rows.

As for outputting .C
·C++
·Java
as bulleted text, you can't really achieve that by inserting bullets into Excel; you should instead insert the un-bulleted text (in Excel) into bulleted paragraphs in Word. To do that, of course, you'd need to have <<subjects>> in a bulleted paragraph in Word.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Cell Text to paste into Find/Replace CBarry Word VBA 2 02-16-2017 04:37 AM
how to replace a text in word by cell value (bulleted text) using macro Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
how to replace a text in word by cell value (bulleted text) using macro Macro to search warning text style and replace the text color rohanrohith Word VBA 3 11-27-2014 01:08 PM
Macro to find coloured text and replace with form-field/formtext containing that text tarktran Word VBA 1 11-26-2014 08:12 AM
how to replace a text in word by cell value (bulleted text) using macro Word VBA Macro to Find and Replace based on the Alt Text of an Image bennymc Word VBA 1 01-27-2014 04:23 PM

Other Forums: Access Forums

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