rdy123 rdy
asked on
macro for active word document
hi,
i wrote a code in excel, where i want to replace few text with the excel.
now the issue is, i work on same file and want to replace the text once the word document is open instead of opening again and replace it.
please suggest.
below is the code.
Sub from()
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim WA As Object
pathh = "C:\Templates\xxx.docx"
Set WA = CreateObject("Word.Applica tion")
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFor matting
WA.Selection.Find.Replacem ent.ClearF ormatting
With WA.Selection.Find
.Text = "abc"
.Replacement.Text = Cells(Application.ActiveCe ll.Row, 15).Value
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
WA.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub sent()
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim WA As Object
pathh = "C:\Templates\xxx.docx"
Set WA = CreateObject("Word.Applica tion")
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFor matting
WA.Selection.Find.Replacem ent.ClearF ormatting
With WA.Selection.Find
.Text = "dddd, mmmm dd, yyyy t:tt"
.Replacement.Text = Cells(Application.ActiveCe ll.Row, 17).Value & " " & Cells(Application.ActiveCe ll.Row, 18).Value
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
WA.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
once the pathh = "C:\Templates\xxx.docx" is open,i want to keep this open and run the sent macro and replace the text,please suggest
i wrote a code in excel, where i want to replace few text with the excel.
now the issue is, i work on same file and want to replace the text once the word document is open instead of opening again and replace it.
please suggest.
below is the code.
Sub from()
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim WA As Object
pathh = "C:\Templates\xxx.docx"
Set WA = CreateObject("Word.Applica
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFor
WA.Selection.Find.Replacem
With WA.Selection.Find
.Text = "abc"
.Replacement.Text = Cells(Application.ActiveCe
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
WA.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub sent()
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim WA As Object
pathh = "C:\Templates\xxx.docx"
Set WA = CreateObject("Word.Applica
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFor
WA.Selection.Find.Replacem
With WA.Selection.Find
.Text = "dddd, mmmm dd, yyyy t:tt"
.Replacement.Text = Cells(Application.ActiveCe
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
WA.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
once the pathh = "C:\Templates\xxx.docx" is open,i want to keep this open and run the sent macro and replace the text,please suggest
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi,
this is continuation of the above scenario,
i want to copy the whole content of word document to outlook,but the pathh = "C:\Templates\xxx.docx" is already opened by above code,i want to keep this open and run the below macro and copy the whole content to outlook,please suggest
the code which i run is the below,
Sub emailFromDoc()
Dim wd As Object, editor As Object
Dim doc As Object
Dim oMail As Object
Dim objOutlook As Object
Set wd = CreateObject("Word.Applica tion")
Set doc = wd.Documents.Open("C:\Temp lates\xxx. docx")
doc.Content.Copy
doc.Close
Set wd = Nothing
Set objOutlook = CreateObject("Outlook.Appl ication")
Set oMail = objOutlook.CreateItem(olMa ilItem)
'Set oMail = Application.CreateItem(olM ailItem)
With oMail
.HTMLBody = Replace(.HTMLBody, "<<Company1>>" , CompanyName)
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
End With
End Sub
the document is already opened and want to copy the content to outlook. please suggest.thank you in advance.
this is continuation of the above scenario,
i want to copy the whole content of word document to outlook,but the pathh = "C:\Templates\xxx.docx" is already opened by above code,i want to keep this open and run the below macro and copy the whole content to outlook,please suggest
the code which i run is the below,
Sub emailFromDoc()
Dim wd As Object, editor As Object
Dim doc As Object
Dim oMail As Object
Dim objOutlook As Object
Set wd = CreateObject("Word.Applica
Set doc = wd.Documents.Open("C:\Temp
doc.Content.Copy
doc.Close
Set wd = Nothing
Set objOutlook = CreateObject("Outlook.Appl
Set oMail = objOutlook.CreateItem(olMa
'Set oMail = Application.CreateItem(olM
With oMail
.HTMLBody = Replace(.HTMLBody, "<<Company1>>"
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
End With
End Sub
the document is already opened and want to copy the content to outlook. please suggest.thank you in advance.
You're welcome! Glad to help.
Please open a new question and post a link to this question there if required
Please open a new question and post a link to this question there if required
ASKER