targeter Posted August 8, 2010 Share Posted August 8, 2010 (edited) I am trying to copy contents from a webpage into word 2007 doc automatically. Everything seems to be working until I get to word. I looked that code from this example, http://www.autoitscript.com/forum/index.php?showtopic=29712. However, I can't get it to run. $word = ObjCreate("Word.Application") $word.visible = False $word.Documents.open(@ScriptDir & "\resume.doc") $word.Selection.TypeText( "november 26 " ) $word.Selection.Font.Bold = True $word.Selection.TypeText( "" ) $word.Selection.Font.Bold = False $word.Selection.TypeText( "." ) $word.ChangeFileOpenDirectory( @ScriptDir ) $word.Activedocument.SaveAs(@ScriptDir & "\resume.doc" ) $word.Application.Quit Testing this code seperately from mine seems to fail for me. I'm not sure what I am doing wrong. It seems like a COM error. I am getting error on the document.open lines. It returns "Error: The requested action with this object has failed." Edited August 8, 2010 by targeter Link to comment Share on other sites More sharing options...
Tvern Posted August 8, 2010 Share Posted August 8, 2010 If I provide resume.doc the above script works for me. (after adding a linebreak in line 5 & 6) I'm running Word 2007 on win7. I can think of two reasons for your error: 1: resume.doc does not exist: use FileExists() to check first. 2: The filepath has to be within quotes. This is sometimes true for paths containing spaces, but I can't reproduce the error this way. 3: The default filetype for word 2007 is docx. Are you sure you created a doc file? P.s. If you are using an object variable multiple times like this you might want to check out the With statement. Link to comment Share on other sites More sharing options...
targeter Posted August 8, 2010 Author Share Posted August 8, 2010 (edited) If I provide resume.doc the above script works for me. (after adding a linebreak in line 5 & 6) I'm running Word 2007 on win7. I can think of two reasons for your error: 1: resume.doc does not exist: use FileExists() to check first. 2: The filepath has to be within quotes. This is sometimes true for paths containing spaces, but I can't reproduce the error this way. 3: The default filetype for word 2007 is docx. Are you sure you created a doc file? P.s. If you are using an object variable multiple times like this you might want to check out the With statement. $word = ObjCreate("Word.Application") $word.visible = False $word.Documents.opn("C:\TEST\test.docx") $word.Selection.TypeText( "november 26 " ) $word.Selection.Font.Bold = True $word.Selection.TypeText( "" ) $word.Selection.Font.Bold = False $word.Selection.TypeText( "." ) $word.ChangeFileOpenDirectory( @ScriptDir ) $word.Activedocument.SaveAs("C:\test\test.docx" ) $word.Application.Quit I changed up the path to avoid the space thing. Could it have something to do with the x64 OS? I tried the Word.au3 option and _WordCreate words. however, I am trying to cut down on lines of code and the memory consumption of the script. In the case above I created a blank test.docx file. Edited August 8, 2010 by targeter Link to comment Share on other sites More sharing options...
seandisanti Posted August 8, 2010 Share Posted August 8, 2010 $word = ObjCreate("Word.Application") $word.visible = False $word.Documents.opn("C:\TEST\test.docx") $word.Selection.TypeText( "november 26 " ) $word.Selection.Font.Bold = True $word.Selection.TypeText( "" ) $word.Selection.Font.Bold = False $word.Selection.TypeText( "." ) $word.ChangeFileOpenDirectory( @ScriptDir ) $word.Activedocument.SaveAs("C:\test\test.docx" ) $word.Application.Quit I changed up the path to avoid the space thing. Could it have something to do with the x64 OS? I tried the Word.au3 option and _WordCreate words. however, I am trying to cut down on lines of code and the memory consumption of the script. yes. there's another thread that explains out the issues of interacting with COM from 64 because COM elements are 32 if i remember correctly Link to comment Share on other sites More sharing options...
targeter Posted August 8, 2010 Author Share Posted August 8, 2010 yes. there's another thread that explains out the issues of interacting with COM from 64 because COM elements are 32 if i remember correctly Dang... So if I run this in a 32-bit windows I should be good to go? Link to comment Share on other sites More sharing options...
seandisanti Posted August 8, 2010 Share Posted August 8, 2010 Dang... So if I run this in a 32-bit windows I should be good to go?it would explain why others trying your code are not having the same issue; and would be consistent with the findings on the other thread, so yes Link to comment Share on other sites More sharing options...
targeter Posted August 8, 2010 Author Share Posted August 8, 2010 it would explain why others trying your code are not having the same issue; and would be consistent with the findings on the other thread, so yesThanks! need to get another vm session running then. Sorry if this seemed too generic of a question. I am trying to run down all possible issues before I finish up my script. Link to comment Share on other sites More sharing options...
seandisanti Posted August 8, 2010 Share Posted August 8, 2010 Thanks! need to get another vm session running then. Sorry if this seemed too generic of a question. I am trying to run down all possible issues before I finish up my script.no worries man, we've all been there Link to comment Share on other sites More sharing options...
Tvern Posted August 8, 2010 Share Posted August 8, 2010 Actually I'm running it on win 7 x64 without issues. I'm even using the x64 version of autoit. You could try using the 32 bit version of autoit without having to use a 32bit OS though. The only problems I've noticed regarding this was with GUICtrlCreateObj(); trying to embed a 32bit object in a 64bit app. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted August 9, 2010 Moderators Share Posted August 9, 2010 however, I am trying to cut down on lines of code and the memory consumption of the script. In the case above I created a blank test.docx file. You'd rather save a miniscule amount of memory and sacrifice the error handling the is built into Word.au3? If you are using a 64-bit OS, 64-bit AutoIt, and SciTE as your editor, just add the follow to the top of the script. #AutoIt3Wrapper_UseX64=n Link to comment Share on other sites More sharing options...
targeter Posted August 9, 2010 Author Share Posted August 9, 2010 You'd rather save a miniscule amount of memory and sacrifice the error handling the is built into Word.au3? If you are using a 64-bit OS, 64-bit AutoIt, and SciTE as your editor, just add the follow to the top of the script. #AutoIt3Wrapper_UseX64=n You're probably right on the mem. The script is going be tied in with multiple other objects and the way in which I am going to make the calls made it initially planed out to be a difference not necessarily in memory but at least in coding length. I think I figured out a way to go with Word.au3. But I am still having trouble with your suggestion. I wonder if it has anything to do with Windows XP x64. I'm loading up a win7 x64 to try this out shortly though. Link to comment Share on other sites More sharing options...
targeter Posted August 9, 2010 Author Share Posted August 9, 2010 Actually I'm running it on win 7 x64 without issues. I'm even using the x64 version of autoit. You could try using the 32 bit version of autoit without having to use a 32bit OS though.The only problems I've noticed regarding this was with GUICtrlCreateObj(); trying to embed a 32bit object in a 64bit app.I am runnng native x64 as well. I am using win7 x64. Are you running this with any headers or as is? Link to comment Share on other sites More sharing options...
Tvern Posted August 9, 2010 Share Posted August 9, 2010 I am runnng native x64 as well. I am using win7 x64. Are you running this with any headers or as is?I'm not using any headers and my default for running scripts is 64bit. My default for compiling is 32 bit, but 64 bit compiling worked aswell. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now