VBA Site contains VBA code to create macros in WORD EXCEL ACCESS OUTLOOK

 

1) Opening Access' database

Dim accessApp

Set accessApp = CreateObject("Access.Application")

accessApp.Visible = True

accessApp.UserControl = True

accessApp.OpenCurrentDataBase ("C:\MyPath\Database.accdb")

 

2) Opening Excel file

Dim excelApp As Object

Set excelApp = CreateObject("Excel.Application")

excelApp.Visible = True

excelApp.Workbooks.Open "C:\MyPath\File.xlsx", True, False

Set excelApp= Nothing

 

3) Opening any applications by *.exe

Dim x As Variant

Dim path As String

Set the Path variable equal to the path of your program's installation

path = "C:\Program Files (x86)\APP\application.exe"

x = Shell(path, vbNormalFocus)

 

4) Opening TXT file, if user_name is allowed

Dim user_name As String

user_name = Environ("UserName")

If user_name = "YourWindowsLogin" Then

Dim MyTxtFile

MyTxtFile = Shell("C:\WINDOWS\notepad.exe C:\YourFolder\SQL.txt", 1)

Else:

End If

 

5) Opening Word file

Dim Wordapp as Object

Dim Docapp as Object

Set Wordapp = CreateObject("Word.Application")

Set Docapp = Wordapp.Documents.Open("C:\MyWordFilee.docx")

Wordapp Visible = True

 

6) Opening PDF file

Sub Opening_pdf()

x = "C:\myfile.pdf"

y = "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"

'1st way

ThisWorkbook.FollowHyperlink x

'2nd way

Shell y & " " & x, vbNormal '2nd way

End Sub



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl