Hi
This is probably a stupid question - so apologies in advance.
Is it possible to open a file (in this a text file) as the last thing in a VBA macro and exit Word VBA? Basically, I am trying to open a text file after completing some VBA work.
Thanks.
Robie.
Open a TXT file while exiting Word VBA
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Open a TXT file while exiting Word VBA
Just include something like
before the end of your macro
Code: Select all
Dim fileTextfile
fileTextfile = Shell("C:\WINDOWS\notepad.exe C:\folder\filename.txt", 1)
StuartR
-
- Administrator
- Posts: 78586
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open a TXT file while exiting Word VBA
And add
Application.Quit
if you want to exit Word. If you want to save any open and modified documents, use
Application.Quit SaveChanges:=True
If you want to close all open documents without saving changes, use
Application.Quit SaveChanges:=False
Application.Quit
if you want to exit Word. If you want to save any open and modified documents, use
Application.Quit SaveChanges:=True
If you want to close all open documents without saving changes, use
Application.Quit SaveChanges:=False
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 12618
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Open a TXT file while exiting Word VBA
Hans,
I assumed that the intention was to exit VBA, rather than to exit Word
I assumed that the intention was to exit VBA, rather than to exit Word
StuartR
-
- Administrator
- Posts: 78586
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Open a TXT file while exiting Word VBA
I agree that that's what Robie requested. But just in case he meant something else...
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 1320
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Open a TXT file while exiting Word VBA
And if you want to open the text file in Word instead of in Notepad, put this line last in the macro:
Code: Select all
Documents.Open "C:\folder\filename.txt"
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: Open a TXT file while exiting Word VBA
Apologies for late reply but wasn't around until today.
Thank you Stuart, Hans and Jay.
I went with Stuart's suggestion as it works for me wonderfully.
THANK YOU VERY MUCH -
Thank you Stuart, Hans and Jay.
I went with Stuart's suggestion as it works for me wonderfully.
THANK YOU VERY MUCH -