Closing Notepad from Excel using VBA


"Excel VBA Help"

 

Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

New Reply
Thread Tools Rate Thread Display Modes
  #1  
Unread 28th March 2012, 16:27
magnusflett's Avatar
magnusflett magnusflett is offline
Junior Member
MS Office Version: MS Office 2003
MS Office Skill Level: Can use VBA
 
Join Date: Mar 2012
Location: Ipswich, England
Age: 62
Posts: 3
Posts Per Day: 0.00
My Top Tip Count: 0
Thanks to others: 0
Thanked 0 Times in 0 Posts
Reputation: 10 (3) magnusflett is on a distinguished road
England
Post Closing Notepad from Excel using VBA
     Excel: VBA   


Can I close Notebook.exe from VBA?

I have a VBA program that writes calculated results to a text file. I can access this output file clicking a button and using the Shell command, typically:
VBA CODE:
Private Sub OutputLongButton_Click() 
    outputLongFile = "C:\RS01outputLongFile.txt" 
    RetVal = Shell("notepad.exe " & outputLongFile, vbNormalFocus) 
End Sub 
This works fine and notebook can be closed manually after viewing the file.

I also want to view the file whilst the calculation is halted using a YES/NO box. I can view the file with a similar routine to that above, but can I close notebook from VBA?

The file is displayed during the last part of my main calculation program:
VBA CODE:
outputLongFile = "C:\RS01outputLongFile.txt" 
RetVal = Shell("notepad.exe " & outputLongFile, vbMinimizedNoFocus) 
J = 0 'Reset time to zero
Call KeyboardInput 
If doAgainFlag = True Then Goto 200 
End Sub 
The Keyboard Input subroutine is the YES/NO box and is:
VBA CODE:
Sub KeyboardInput() 
    iReply = MsgBox(Prompt:="Do you wish to ammend the data using the keyboard?", _ 
    Buttons:=vbYesNo, Title:="Keyboard Input") 
    If iReply = vbYes Then 
        doAgainFlag = True 'Recalculate
        dataFlag = False 'Keyboard input
        Call ResetAll 'Reset for recalculation
    ElseIf iReply = vbNo Then 
        doAgainFlag = False 'Finished
        Exit Sub 
    End If 
End Sub 
Any suggestions?


Last edited by Leith Ross; 28th March 2012 at 17:04.
The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #2  
Unread 28th March 2012, 16:42
snb's Avatar
snb snb is offline
Forum VIP
MS Office Version: > Office 97
MS Office Skill Level: Interested
 
Join Date: Feb 2011
Location: Europe
Posts: 1,152
Posts Per Day: 0.99
My Top Tip Count: 0
Thanks to others: 0
Thanked 257 Times in 251 Posts
Reputation: 4370 (58) snb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond reputesnb has a reputation beyond repute
Default Re: Closing Notepad from Excel using VBA

------ Register to get rid of these "In Post" ads! ------


Warning

Warning



Sorry but you need to register for FREE to see the rest of these posts. Please click HERE to register.

We only allow guests to see the first post of every thread to keep valuable resources for our members.






  #3  
Unread 28th March 2012, 20:06
Leith Ross's Avatar
Leith Ross Leith Ross is offline
The Code Cage Staff
Solution Centre Professional
MS Office Version: 2000, 2003 & 2010
MS Office Skill Level: Expert in VBA
 
Join Date: Dec 2008
Location: San Bruno, CA USA
Age: 56
Posts: 424
Posts Per Day: 0.22
My Top Tip Count: 0
Thanks to others: 2
Thanked 44 Times in 42 Posts
Reputation: 835 (18) Leith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to beholdLeith Ross is a splendid one to behold
USA
Default Re: Closing Notepad from Excel using VBA

------ Register to get rid of these "In Post" ads! ------


Warning

Warning



Sorry but you need to register for FREE to see the rest of these posts. Please click HERE to register.

We only allow guests to see the first post of every thread to keep valuable resources for our members.





__________________
Sincerely,
Leith Ross

Microsoft Office Help


Last edited by Leith Ross; 28th March 2012 at 20:08.
The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

  #4  
Unread 24th April 2012, 17:14
magnusflett's Avatar
magnusflett magnusflett is offline
Junior Member
MS Office Version: MS Office 2003
MS Office Skill Level: Can use VBA
 
Join Date: Mar 2012
Location: Ipswich, England
Age: 62
Posts: 3
Posts Per Day: 0.00
My Top Tip Count: 0
Thanks to others: 0
Thanked 0 Times in 0 Posts
Reputation: 10 (3) magnusflett is on a distinguished road
England
Default Re: Closing Notepad from Excel using VBA

------ Register to get rid of these "In Post" ads! ------


Warning

Warning



Sorry but you need to register for FREE to see the rest of these posts. Please click HERE to register.

We only allow guests to see the first post of every thread to keep valuable resources for our members.






The Code Cage Advertisment
Advertisement

To stop seeing these ads and get other benefits check This page!

New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
closing, excel, notepad, vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 05:02.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University