OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 439
- Office Version
- 2019
- Platform
- Windows
Hello all and thanks in advance for any assistance you may provide.
I would like to update the following lines of the MS Excel Code Provided.
I obtained this from another site or post....cannot recall where. I have found several different versions, but I cannot seem to go those to work, so I am working on completing the following.
I would like to update the following lines of the MS Excel Code Provided.
VBA Code:
'Code to save any changes made only to the file that was open with this code
VBA Code:
'Code to only close the file open with this code (do not close MS Word)
I obtained this from another site or post....cannot recall where. I have found several different versions, but I cannot seem to go those to work, so I am working on completing the following.
VBA Code:
Sub Open_Word_Document()
'Opens a Word Document from Excel
'_______________________________________________________________________________________________________
'Turn off alerts, screen updates, and automatic calculation
'Application.DisplayAlerts = False
'Application.ScreenUpdating = False
'Application.Calculation = xlManual
'_______________________________________________________________________________________________________
'Dimensioning
'Dimensioning
Dim objWord As Object
Dim aFilePath As String
Dim aFileName As String
Dim aFileName_N_Path As String
'Settting Object
Set objWord = CreateObject("Word.Application")
'Makes MS Word Visible
objWord.Visible = True
'Change the directory path and file name to the location of your document
'Setting file name and path
aFilePath = "J:\MPF\00. Test"
aFileName = "Application - Tasks 2017-08-07.docx"
'If Directory does not have a "\" at the end, adds one
If Right(aFilePath, 1) <> "\" Then aFilePath = aFilePath & "\"
'Combines file path and file name
aFileName_N_Path = aFilePath & aFileName
'Opens the word document
objWord.Documents.Open aFileName_N_Path
'Code to make changes
'Code to save any changes made only to the file that was open with this code
'Code to only close the file open with this code (do not close MS Word)
End Sub