Sign in to follow this  
Followers 0
Rorax

Copy a picture, Paste it into Word, Move Picture to different folder

11 posts in this topic

#1 ·  Posted (edited)

#include <Misc.au3>
$varDate = "2006-09-05"
$search = FileFindFirstFile("H:\Scannade\*.tif")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No images found")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    If NOT FileExists("H:\Scannade\" & $VarDate) then
    DirCreate("H:\Scannade\" & $VarDate)
EndIf
_ClipPutFile("H:\scannade\" & $file)
 If NOT ProcessExists("winword.exe") THEN  
   Run(@ProgramFilesDir & "\Microsoft Office\office\winword.exe") 
   WinWaitActive("Dokument1 - Microsoft Word")
 EndIf
 If WinExists("Dokument1") THEN 
   WinActivate("Dokument1", "")
   WinSetTitle("Dokument1", "", "Lex")
   WinSetstate("Lex", "", @SW_Maximize)
 EndIf
Send("!a")
Filemove ("H:\scannade\" & $file, "H:\scannade\" & $VarDate)  
WEnd

Basically what I want it to do is: Search a folder for TIF files, if it finds one,It starts up word, renames its title to Lex it, send the files one by one to clipboard, send CTRL + V (paste) into a word dokument, then moves the just pasted original TIF file into a new folder (with the temp date of today which it will create if it doesnt exist, will use a function later when I get get this first part to work). And then repeat untill it finds no more TIF files.

But it cant actually use CTRL + V into MS Word, its greyed out. But I can press CTRL + V on the desktop and it will copy in the file I wanted. Is there a better way to paste in stuff except sending CTRL + V through send? Tried ClipGet but couldnt get it to work either.

Would appreciate any help!

Regards,

Rorax

Edited by Rorax

Share this post


Link to post
Share on other sites



Have you tried big_daddy's word udfs?

http://www.autoitscript.com/forum/index.ph...c=30461&hl=


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

No I havent tried it, I'll see if I can incorporate some of its funcions. But since english isnt my native language and I'm kind of new into programming I cant really find out precisly how it works.

Since I dont have the script on this computer I cant try it out yet. But I would guess that what I'm looking for is either:

_WordAttach or _WordDocAdd, but the wording in the help file kinds of confuses me.

I'll have a look at it tomorrow. Thanks for your advice.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm working on something that may work for you. I'll let you know as soon as I have something.

Edit: What type of .tif files are these?

Edited by big_daddy

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Its scanned images, the script I'm doing starts Windows XP - Camera and Scanner Wizard, Set the settings to 200 DPI, Black & White, A4 standard size and names the pictures after todays date.

Then it makes a loop, checks a folder which images exist and tries to insert them into word and move them into a new folder to confirm that they are inserted into word. (which is the part I posted and having problems with)

Not sure if I'm going to stick with .tif files or make them into .jpg instead. But basically you can insert them into word if you do

(Using swedish version of Word so just translating it directly)

Start word -> Insert -> Image Object -> From file -> (Browse to file) and click OK

Edited by Rorax

Share this post


Link to post
Share on other sites

See if this works for you.

#include <Date.au3>
#include <Word.au3>

_WordErrorHandlerRegister ()

$vDate = StringReplace(_NowCalcDate(), "/", "-")
$sPath = "H:\Scannade\"
$search = FileFindFirstFile($sPath & "*.tif")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No images found")
    Exit
EndIf

If Not FileExists($sPath & $vDate) Then
    DirCreate($sPath & $vDate)
EndIf

$oWordApp = _WordCreate ()
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$oWindow = $oDoc.ActiveWindow
$owindow.Caption = "Lex"
$owindow.WindowState = 1

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    $copy = _CopyToWord($sPath & $file)
    FileMove($sPath & $file, $sPath & $vDate & "\" & $file, 8)
WEnd

Func _CopyToWord($h_file)
    $oShape = _WordDocAddPicture($oDoc, $h_file, False, True)
    $oShape.Range.InsertAfter (@CRLF)
EndFunc   ;==>_CopyToWord

Func _WordDocAddPicture($o_object, $s_FileName, $b_LinkToFile = False, $b_SaveWithDocument = False)
    If Not IsObj($o_object) Then
        __WordErrorNotify ("Error", "_WordDocAddPicture", "$_WordStatus_InvalidDataType")
        SetError($_WordStatus_InvalidDataType, 1)
        Return 0
    EndIf
    
    $o_Shape = $o_object.InlineShapes.AddPicture ($s_FileName, $b_LinkToFile, $b_SaveWithDocument)
    Return $o_Shape
EndFunc   ;==>_WordDocAddPicture

Share this post


Link to post
Share on other sites

I would be nice to know if this worked or not. :)

Share this post


Link to post
Share on other sites

I would be nice to know if this worked or not. :)

Ha!... Good luck with that request... The forum is like Clinton in a brothel, get in, get what you want, and get out before Hillary kicks your ass.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Sorry been quite busy so havent had time to check the thread for a while. I always try to follow threads I make or ask questions in since its nice to actually thank the people that help you so they dont think your a leech or something. And it encourages them to help more people when they actually get a responce and not silence once the solution is presentated.

I'll try it as soon as I can and get back to you.

edit: Just tried it on my work machine. And it works flawless. Trying to understand what everything in the script does now hehe in case I need to replicate some of its functions.

Thanks a lot for taking the time to help me out with this. I just love the functionality that Autoitv3 has. Trying to learn more about scripting it myself. But its a long process to go untill you get good at it if you havent done much scripting before.

Edited by Rorax

Share this post


Link to post
Share on other sites

Hi,

This works for me;

Do you know how to place successive pictures across the page?

I have had trouble with the commands in my word macros;

$o_Shape = $o_object.InlineShapes.AddPicture ($s_FileName, $b_LinkToFile, $b_SaveWithDocument)
Randall

Share this post


Link to post
Share on other sites

@randallc - Just remove the below line.

$oShape.Range.InsertAfter (@CRLF)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0