How to Browse Application using VBA ?

Ans : We can open Various Application using Excel VBA

Open Specific Folder

Sub BrowseFolder()
Dim MyFldr As String

'Folder Path
MyFldr="D:\LG\Macros\"

Shell "C:\WINDOWS\explorer.exe " " " & MyFldr & " ",VbMaximizedFocus

End Sub
Open Website 

Sub OpenURL() 
Dim MyLink As String 

MyLink="https://excelvbatipstricks.blogspot.com"

ActiveWorkbook.FollowHyperLink:= MyLink,NewWindow:=True 

End Sub

Open Text File 

Sub OpenTxtFile()
Dim StrFile As Variant

'Add Space After .exe
StrFile = Shell("Notepad.exe "& "D:\LG\Test.txt",VbMaximizedFocus)

End Sub
 
⚝ Open PDF File 

Sub OpenPdf()
Dim Path As String

'Pdf Path
Path = "D:\LG\Test2.pdf"

ActiveWorkbook.FollowHyperLink
Path

End Sub
 
Open Word Document

Sub OpenWordDoc()
Dim WordFile As Object

Set WordFile =CreateObject("Word.Application")

WordFile.Visible=True

WordFile.Documents.Open "D:\LG\Test3.Docs"

End Sub

⚝ Open Powerpoint Presentation

Sub OpenPpt()
Dim Ppt As Object

Set Ppt = CreateObject("Powerpoint.Application")

Ppt.Visible = True

Ppt.Presentations.Open "D:\LG\Test3.pptx"
End Sub
 
⚝ Open Access Database 

➩ To open access database , we can use below two methods
1) Late Binding
2) Early Binding

1) Late Binding : We have to create object  To Open Access Database

Sub OpenDB_LateBinding()
Dim AccApp As Object
Dim SPath As String

SPath ="D:\Access\LG.accdb"

Set AccApp = CreateObject("Access.Application")

AccApp.OpenCurrentDatabase(SPath)

AccApp.Visible = True
 
End Sub

 2) Early Binding : We have to Add (Select) Reference  To Open Access Database

⚝ VBA Editor ➩ Tools ➩ Reference ➩ 
1) Microsoft Access xxx Object Library
2) Microsoft Activex Data Object xxx Library
  [ 14.0 , 6.1 Version Can be different As per System ]


Sub OpenDB_EarlyBinding()
Dim AccApp As  Access.Application
Dim SPath As String

SPath ="D:\Access\LG.accdb"

Set AccApp = New Access.Application

AccApp.OpenCurrentDatabase(SPath)

AccApp.Visible = True
 
End Sub

Post a Comment

Previous Post Next Post