This works Thank you so much.
But can u tell me why my code is skipping the lines which add reference libraries automatically
This works Thank you so much.
But can u tell me why my code is skipping the lines which add reference libraries automatically
Hii..
I am trying to draft mail via outlook using VBA.
since we need to add outlook library/ scripting library (for using file system object), I incorporated vba code to add libraries.
Code is working fine if the it only have the lines to add library. In this case it is adding the required library.
But when i add outlook object declaration to the code, it is skipping the code lines which adds libraries and throwing 'compiler error : user defined type not defined'
If the libraries are already added this is running fine. In any case it is skipping the lines highlighted in red.
Please help
<Code>
Option Explicit
Sub DraftMail()
On Error Resume Next
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Microsoft Office\root\Office16\MSOUTL.OLB" ' adding outlook library
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\System32\scrrun.dll"
On Error GoTo 0
Dim MyOutlook As Outlook.Application
Dim DraftMail As Outlook.MailItem
Set MyOutlook = New Outlook.Application
Set DraftMail = MyOutlook.CreateItem(olMailItem)
With DraftMail
.BodyFormat = olFormatHTML
.Display
.HTMLBody = "Dear ABC" & vbNewLine & .HTMLBody
.To = "[email protected]"
.Subject = "xyz"
.Attachments.Add "ref"
End With
End Sub
</code>
I am new to excel vba macro. I am trying to login to a website using the below code, which gives me Runtime error 91"object variable not set".
please help
i am pasting code below
it is giving me error @ UserNameIp.Value = "xxxxxxx(username)"
Sub browserlogin()
Dim ieDoc As MSHTML.HTMLDocument
Dim MyBrowser As SHDocVw.InternetExplorer
Dim UserNameIp As MSHTML.HTMLInputElement
Dim Password As MSHTML.HTMLInputElement
Dim NextButton As MSHTML.HTMLInputElement
Dim SignInButton As MSHTML.HTMLInputElement
Dim KeepMeLoggedInCheckBox As MSHTML.HTMLInputElement
Dim MyURL As String
MyURL = "(URL HERE)"
Set MyBrowser = New SHDocVw.InternetExplorer 'Create INternet Explorer Object
MyBrowser.navigate MyURL ' Navigate to URL
Do Until MyBrowser.readyState = READYSTATE_COMPLETE: Loop 'wait for page to load
Set ieDoc = MyBrowser.document ' get document object
MyBrowser.Visible = True
Application.Wait Now() + #12:00:02 AM#
Set UserNameIp = ieDoc.all.Item("userInput")
Set NextButton = ieDoc.all.Item("login-button")
UserNameIp.Value = "xxxxxxx(username)"
Application.Wait Now() + #12:00:02 AM#
NextButton.Click
Application.Wait Now() + #12:00:02 AM#
Set Password = ieDoc.all.Item("passwordInput")
Password.Value = "xxxxx(password)"
Application.Wait Now() + #12:00:02 AM#
Set SignInButton = ieDoc.all.Item("login-button")
Application.Wait Now() + #12:00:02 AM#
SignInButton.Click
End Sub
Display More