how to select excel's cell via Macro Scheduler

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
windwing
Newbie
Posts: 3
Joined: Tue Jul 04, 2017 5:45 am

how to select excel's cell via Macro Scheduler

Post by windwing » Wed Jul 19, 2017 8:22 am

Topic: how to select excel's cell via Macro Scheduler

I'm writing a script to copy text message from docx file
to excel file.

the method i used is "use select all and copy all text
in docx file and paste it in excel"

my script is work except one thing, i can't select which
cell in excel to paste the message.

the message will be paste on cell the was select last time.

Plaese show me how to select excel's cell with script.

there is my code

Code: Select all

//set file destination
Let>OPfilename=C:\W2E\input.xlsx
Let>IPfilename=C:\W2E\data.docx
Let>FileStauts=00

  //Check Exists File
  IfFileExists>OPfilename

  //Output File Found!
  Let>FileStauts= %FileStauts% + 1

  Endif

  IfFileExists>IPfilename

  //Input File Found!
  Let>FileStauts= %FileStauts% + 10

  Endif


  if>Filestauts=11
  
  MessageModal>Files is ready! Press Enter to Begin.
   
    XLOpen>C:\W2E\input.xlsx,,xlBook
    WaitWindowOpen>input - Excel
    ExecuteFile>C:\W2E\data.docx,
    WaitWindowOpen>data - Word
    
    //Copy all text in word file
    SetFocus>data - Word
    Wait>0.5
    Press LCTRL
    Send>a
    Wait>0.5
    Press LCTRL
    Send>c
    
    //Paste all text in excel
    SetFocus>input - Excel
    WaitWindowFocused>input - Excel
    Wait>0.5
    Press LCTRL
    Send>v
    
  Else
  
  MessageModal>Input File or Output File is not Found!
  
  Endif

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: how to select excel's cell via Macro Scheduler

Post by Marcus Tettmar » Wed Jul 19, 2017 8:33 am

Rather than use paste, can't you just use the XLSetCell command?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

windwing
Newbie
Posts: 3
Joined: Tue Jul 04, 2017 5:45 am

Re: how to select excel's cell via Macro Scheduler

Post by windwing » Thu Jul 20, 2017 5:13 am

thank you for advice.

I changed method to "after copy text, use GetClipBoard to get data and put into excel by XLSetCell".
It work but something still off.

the text data has 3 lines.
when i put it with XLSetCell, all of 3 lines was put into single cell.

are there a ways to put those 3 line in diffrent cell? like paste do.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: how to select excel's cell via Macro Scheduler

Post by Marcus Tettmar » Mon Jul 24, 2017 9:54 am

You'd need to parse out each line and XLSetCell each bit one per cell.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

windwing
Newbie
Posts: 3
Joined: Tue Jul 04, 2017 5:45 am

Re: how to select excel's cell via Macro Scheduler

Post by windwing » Tue Jul 25, 2017 1:54 am

I did it. its's not very effective way but the result is what i want.
Method is before paste text use Find function in excel to find first head of column ("Member code") close Find window arrow down one time and paste.

Code: Select all

//Data Sorting: Word to Excel V4
//Complete

//set file destination
Let>OPfilename=C:\W2E\input.xlsx
Let>IPfilename=C:\W2E\data.docx
Let>FileStauts=00

  //Check Exists File
  IfFileExists>OPfilename

  //Let>FileStauts= Output File Found!
  Let>FileStauts= %FileStauts% + 1

  Endif

  IfFileExists>IPfilename

  //Let>FileStauts= %FileStauts% Input File Found!
  Let>FileStauts= %FileStauts% + 10

  Endif


  if>Filestauts=11
  
  MessageModal>Files is ready! Press Enter to Begin.
    XLOpen>C:\W2E\input.xlsx,,xlBook
    WaitWindowOpen>input - Excel
    ExecuteFile>C:\W2E\data.docx,
    WaitWindowOpen>data - Word
    
    //Copy all text in word file
    SetFocus>data - Word
    Wait>0.5
    Press LCTRL
    Send>a
    Wait>0.5
    Press LCTRL
    Send>c
    Release LCTRL
    Wait>0.5
    WaitClipBoard
    GetClipBoard>Clipdata
    Wait>0.5
    
    //Going to Paste all text in excel
    SetFocus>input - Excel
    WaitWindowFocused>input - Excel
    Wait>0.5
    
    //Find Paste Location
    Press LCTRL
    Send>f
    Release LCTRL
    Send>Member code
    Wait>0.5
    Press Enter
    Release Enter
    Wait>0.5
    SetFocus>Find and Replace
    Press ALT
    Press F4
    Wait>0.11
    Release ALT
    Release F4
    Press Down
    
    //Paste Text
    Press LCTRL
    Send>v
    Release LCTRL
    
    
  Else
  
  MessageModal>Input File or Output File is not Found!
  
  Endif

some how, "paste out each line and XLSetCell each bit one per cell" is intersting.
if possible, please show me a simple code how to did it.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts