Hi Andreas,
I copied your code, and I and getting the following error message:
Compile error:
Only commands may appear after End Sub, End Function, or End Property
I will also need to set other subs to refer to other website, will I just add these after the link for the Microsoft one?
Here is the code as I placed it and set [BOLDITALIC] where the Error message is Highlighted:
Option Explicit
Sub SetRef()
On Error Resume Next
'Microsoft Internet Controls
Application.VBE.ActiveVBProject.References.AddFromGuid _
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Const SW_HIDE = 0
Private Const SW_NORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10
Private Const SW_MAX = 10
#If Win64 Then
Private Declare PtrSafe Function GetWindowPlacement Lib "user32" ( _
ByVal hWnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare PtrSafe Function SetWindowPlacement Lib "user32" ( _
ByVal hWnd As LongPtr, lpwndpl As WINDOWPLACEMENT) As Long
#Else
Private Declare Function GetWindowPlacement Lib "user32" ( _
ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" ( _
ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
#End If
Sub Microsoft_Click()
Dim Browser As Object 'SHDocVw.InternetExplorer
Dim WP As WINDOWPLACEMENT
'Create the object
Set Browser = CreateObject("InternetExplorer.Application")
'Setup the size of our variable
WP.Length = Len(WP)
'Get the settings from the window
GetWindowPlacement Browser.hWnd, WP
'Show it maximized (and visible)
WP.showCmd = SW_MAXIMIZE
'Execute
SetWindowPlacement Browser.hWnd, WP
Browser.Navigate ("http://microsoft.com")
End Sub
Then add other copies of "Sub Microsoft_Click()"
Just a feed back I am using Word 2010 under the Windows 7 Operating System.
I am using "Image (ActiveX Control)" for me to click on Picture to load Website, and these are put within the "ThisDocument".
Could this be why I am getting the Error?
Does your code need to be placed within the "Modules"?
Thanks,
Neil