Re: Problems with Python for Windows extensions
Hello, I guess you could reproduce my problem, Kartic. I have tried the one u suggested, but sadly it didn't work for me. I think the COM of pywin is quite tricky, or it might be a bug. I have some friends who also had experience of weird behaviors of pywin32, which makes me skeptical of using it in real app. Thanks KK -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with Python for Windows extensions
The Great 'KK' uttered these words on 9/7/2005 7:57 AM: Hello, I guess you could reproduce my problem, Kartic. I have tried the one u suggested, but sadly it didn't work for me. I think the COM of pywin is quite tricky, or it might be a bug. I have some friends who also had experience of weird behaviors of pywin32, which makes me skeptical of using it in real app. Thanks KK Actually, I have created some robust win32com applications (using Word and Excel) that work consistently on all installed machines. Could it be an Office 2003 quirk? Did some other app of yours crash while using COM? Such crashes could produce unpredictable results in COM related code, from my experience. So, if you think it is worth your time, you could probably investigate it a bit more or better contact Mark Hammond to see if he can help. I don't know if there is a win32com mailing list; if there is one, please post your question there too. Thanks, -Kartic -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with Python for Windows extensions
KK [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] | the code below is taken from M$ technet as an example on using vb | script to do a replace all in word: | | Const wdReplaceAll = 2 | | Set objWord = CreateObject(Word.Application) | objWord.Visible = True | | Set objDoc = | objWord.Documents.Open(K:\Development\Fabricbase\prod\Test.doc) | Set objSelection = objWord.Selection | | objSelection.Find.Text = Contoso | objSelection.Find.Forward = True | objSelection.Find.MatchWholeWord = True | | objSelection.Find.Replacement.Text = Fabrikam | objSelection.Find.Execute ,,wdReplaceAll | | | | | I did a rewrite and made it pythonic: | | from win32com.client import * | | wdReplaceAll = 2 | | objWord = Dispatch(Word.Application) | objWord.Visible = True | | objDoc = | objWord.Documents.Open(K:\Development\Fabricbase\prod\Test.doc) | objSelection = objWord.Selection | | objSelection.Find.Text = Contoso | objSelection.Find.Forward = True | objSelection.Find.MatchWholeWord = True | | objSelection.Find.Replacement.Text = Fabrikam | objSelection.Find.Execute (Replace = wdReplaceAll) | | | However, the document juz loaded up in word but no action was taken. I | am using Word 2003. Any ideas? KK, Your example seemed to work fine for me (Python2.4, Pythonwin build 204, Word 2003) One thing: since you say your document loads up fine I don't know if it is just a typo, but make sure you follow the rules of backslash literals in path names. In other words: K:\Development\Fabricbase\prod\Test.doc should read either rK:\Development\Fabricbase\prod\Test.doc (note the leading r for raw string or K:\\Development\\Fabricbase\\prod\\Test.doc or K:/Development/Fabricbase/prod/Test.doc -- Vincent Wehren -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with Python for Windows extensions
thx for ur reply u r rite that i should use a raw string, but that doesn't solve the problem i am q annoyed by this strange behaviour. i tried to run the script on my friend's pc, which is python2.4 + pywin 204 + office 2000, but same thing happened now i am thinking to generate a vbs from python and run it. i know it is dumb but i dont know other solutions... -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with Python for Windows extensions
Hi, Invoking Execute as shown below works.. I have no explanation why your VB to Py converted code did not work. wdFindContinue = 1 objSelection.Find.Execute('Contosa', False, True, False, False, True, True, wdFindContinue, True, 'Fabrikam', wdReplaceAll, False, False, False, False) This finds 'Contosa' and replaces all occurances with 'Fabricam'. For a full explanation about the arguments to Execute, look it up in the VBA Help. Thanks, -Kartic The Great 'KK' uttered these words on 9/3/2005 11:14 AM: the code below is taken from M$ technet as an example on using vb script to do a replace all in word: Const wdReplaceAll = 2 Set objWord = CreateObject(Word.Application) objWord.Visible = True Set objDoc = objWord.Documents.Open(K:\Development\Fabricbase\prod\Test.doc) Set objSelection = objWord.Selection objSelection.Find.Text = Contoso objSelection.Find.Forward = True objSelection.Find.MatchWholeWord = True objSelection.Find.Replacement.Text = Fabrikam objSelection.Find.Execute ,,wdReplaceAll I did a rewrite and made it pythonic: from win32com.client import * wdReplaceAll = 2 objWord = Dispatch(Word.Application) objWord.Visible = True objDoc = objWord.Documents.Open(K:\Development\Fabricbase\prod\Test.doc) objSelection = objWord.Selection objSelection.Find.Text = Contoso objSelection.Find.Forward = True objSelection.Find.MatchWholeWord = True objSelection.Find.Replacement.Text = Fabrikam objSelection.Find.Execute (Replace = wdReplaceAll) However, the document juz loaded up in word but no action was taken. I am using Word 2003. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Problems with Python for Windows extensions
the code below is taken from M$ technet as an example on using vb script to do a replace all in word: Const wdReplaceAll = 2 Set objWord = CreateObject(Word.Application) objWord.Visible = True Set objDoc = objWord.Documents.Open(K:\Development\Fabricbase\prod\Test.doc) Set objSelection = objWord.Selection objSelection.Find.Text = Contoso objSelection.Find.Forward = True objSelection.Find.MatchWholeWord = True objSelection.Find.Replacement.Text = Fabrikam objSelection.Find.Execute ,,wdReplaceAll I did a rewrite and made it pythonic: from win32com.client import * wdReplaceAll = 2 objWord = Dispatch(Word.Application) objWord.Visible = True objDoc = objWord.Documents.Open(K:\Development\Fabricbase\prod\Test.doc) objSelection = objWord.Selection objSelection.Find.Text = Contoso objSelection.Find.Forward = True objSelection.Find.MatchWholeWord = True objSelection.Find.Replacement.Text = Fabrikam objSelection.Find.Execute (Replace = wdReplaceAll) However, the document juz loaded up in word but no action was taken. I am using Word 2003. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list