Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 25th, 2013, 03:07 AM
pw111970 pw111970 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 pw111970 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 3 sec
Reputation Power: 0
Execute a Python Script from Excel

Hi,

I was not sure if this belonged in this forum - so apologies if I have posted in the wrong area.

I have a Python script which works perfectly and execeutes when I double click in Windows Explorer. I would like to execute the script when I click a button in my Excel spreadsheet.

In my Excel VBA I have used the following command:-

Call Shell(pyPath & pyFile)

pypath ="C:\Python26\python.exe "
pyFile ="script.py"

However, when the code runs I can see the Python icon flash up in my task bar but the script does not run/execute, if I exclude the 'pyFile', the Python interface opens. Can you please tell me where I am going wrong?

Thanks.

Reply With Quote
  #2  
Old January 25th, 2013, 08:56 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
You might not be doing anything wrong. Have your python program exhibit a lasting external symptom.
Code:
import time
time.sleep(8) # hold the window open for a few seconds

# or

with open('a_sign.txt','w') as o:
    o.write('Hello!\n')
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 28th, 2013, 03:56 AM
pw111970 pw111970 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 4 pw111970 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 3 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
You might not be doing anything wrong. Have your python program exhibit a lasting external symptom.
Code:
import time
time.sleep(8) # hold the window open for a few seconds

# or

with open('a_sign.txt','w') as o:
    o.write('Hello!\n')


Thank you for the reply - I used the code and when I execute my VB script all I see is a 'black' python screen and the script does not execute. The strange thing is that it appears to be an intermittent issue - sometimes the script works and other times it doesn't, but I cannot find where the issue lies as I am not making any changes to the VB or Python scripts.

Reply With Quote
  #4  
Old February 8th, 2013, 01:03 AM
pyJer pyJer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Location: California, USA
Posts: 6 pyJer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 10 m 21 sec
Reputation Power: 0
Apply this VBA code to your folders and files. It worked for
me using Excel 2003.
Code:
Private Sub CommandButton1_Click()
Dim pyPrgm As String, pyScript As String
pyPrgm = "C:\Python33\python.exe "
pyScript = "C:\Python33\MyScripts\test1.py"
Call Shell(pyPrgm & pyScript, vbMaximizedFocus)
End Sub

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Execute a Python Script from Excel

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap