Hello guys,
I am new here, and I am new in VBA coding too.
So i have embedded a word document in an excel file, and using VBA, i would like to extract the text from it and copy it in a cell of the excel, as well as the format of the text.
I have been going around few forums, but haven't found a solution to do this. I read that the word file can be taken as an OLEObject, but how do i extract what's in there?
The reason behind that is that I'd like to implement a code to send email using VBA. The body of the email would be taken from that word document.
For the email code i have been using this code which works pretty well, from :https://www.wallstreetmojo.com/vba-send-email-from-excel/
Then I tried to use what was in this doc : Redirecting
But the wDoc.COntent.copy doesn't seem to work for me.
If you guys ave any idea how I could manage to do that, would be very grateful!
Thanks
I am new here, and I am new in VBA coding too.
So i have embedded a word document in an excel file, and using VBA, i would like to extract the text from it and copy it in a cell of the excel, as well as the format of the text.
I have been going around few forums, but haven't found a solution to do this. I read that the word file can be taken as an OLEObject, but how do i extract what's in there?
The reason behind that is that I'd like to implement a code to send email using VBA. The body of the email would be taken from that word document.
For the email code i have been using this code which works pretty well, from :https://www.wallstreetmojo.com/vba-send-email-from-excel/
Code:
Sub SendEmail_Example1()
Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
EmailItem.To = "Hi@gmail.com"
EmailItem.CC = "hello@gmail.com"
EmailItem.BCC = "hhhh@gmail.com"
EmailItem.Subject = "Test Email From Excel VBA"
EmailItem.HTMLBody = "Hi," & vbNewLine & vbNewLine & "This is my first email from Excel" & _
vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"VBA Coder"
Source = ThisWorkbook.FullName
EmailItem.Attachments.Add Source
EmailItem.Send
End Sub
Then I tried to use what was in this doc : Redirecting
But the wDoc.COntent.copy doesn't seem to work for me.
Code:
Sub Test()
Dim Oo As OLEObject
Dim wDoc As Object 'Word.Document
'Search for the embedded Word document
For Each Oo In ActiveSheet.OLEObjects
If InStr(1, Oo.progID, "Word.Document", vbTextCompare) > 0 Then
'Open the embedded document
Oo.Verb xlVerbPrimary
'Get the document inside
Set wDoc = Oo.Object
'Copy the contents to cell A1
wDoc.Content.Copy
Range("A1").PasteSpecial xlPasteValues
'Select any cell to close the document
Range("A1").Select
'Done
Exit For
End If
Next
End Sub
If you guys ave any idea how I could manage to do that, would be very grateful!
Thanks