Author Topic: Clipboard object in VBScript  (Read 5629 times)

Offline ReshmiParakkat

  • Newbie
  • *
  • Posts: 6
Clipboard object in VBScript
« on: October 08, 2009, 09:07:01 am »
Whats the equivalent object that we can use in VBScript in place of
Mercury.Clipboard? Need to copy and Paste few sentences using
VBScript.
 Thanks in advance.

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline ReshmiParakkat

  • Newbie
  • *
  • Posts: 6
Re: Clipboard object in VBScript
« Reply #2 on: October 09, 2009, 01:23:11 am »
Thanks Tarun. But I am trying to copy some thing from a word doc and to put it in an excel cell through a VBScript. I used the Wshellobj.sendkeys "^C" to copy the text, that is working fine, but it is not pasting when I am trying to use Wshellobj.sendkeys "^V", nor could I extract it from clipboard. Please help.

Thanks

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
Re: Clipboard object in VBScript
« Reply #3 on: October 09, 2009, 01:25:17 am »
What is your current code? When you say Word and Excel, are you using the COM APIs to do the same or not?
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline ReshmiParakkat

  • Newbie
  • *
  • Posts: 6
Re: Clipboard object in VBScript
« Reply #4 on: October 09, 2009, 01:31:33 am »
Yes, I am using COM objects.

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
Re: Clipboard object in VBScript
« Reply #5 on: October 09, 2009, 01:42:29 am »
Post your current code and what you exactly want to achieve. I will take a look over the weekend
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline ReshmiParakkat

  • Newbie
  • *
  • Posts: 6
Re: Clipboard object in VBScript
« Reply #6 on: October 09, 2009, 01:50:39 am »
Here is the code

Set objExcel=createobject("Excel.Application")
Set objWord = createobject("Word.Application")
Set obj=createobject("wscript.shell")
Set objDoc = objWord.Documents.Open(word)
Set objWorkBook = objExcel.Workbooks.Open(Excel)
objDoc.Tables(1).Cell(1,2).select
obj.sendkeys "^c"
Set objRange = objExcel.Range("A2")
objRange.select
'now I want to make some changes to the copied text and put it in the cell A2

Thanks
Reshmi
« Last Edit: October 09, 2009, 01:53:17 am by ReshmiParakkat »

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
Re: Clipboard object in VBScript
« Reply #7 on: October 09, 2009, 02:05:07 am »
Try this, i have not tested the same but i guess it should work

Set objExcel=createobject("Excel.Application")
Set objWord = createobject("Word.Application")
Set obj=createobject("wscript.shell")
Set objDoc = objWord.Documents.Open(word)
Set objWorkBook = objExcel.Workbooks.Open(Excel)
objDoc.Tables(1).Cell(1,2).Range.Copy
Set objRange = objExcel.Range("A2")
objRange.select
objExcel.Paste
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline ReshmiParakkat

  • Newbie
  • *
  • Posts: 6
Re: Clipboard object in VBScript
« Reply #8 on: October 09, 2009, 03:32:46 am »
Set Activesheet=objExcel.activesheet
                                  Activesheet.Paste  objExcel.Range("A2")

This works, but the problem is the entire format is lost. objExcel.cells(2,1).value="Something" will retain the format. Thats why I was trying to get the text first, modify it and then put to the specific cell.

Thanks
Reshmi

Offline ReshmiParakkat

  • Newbie
  • *
  • Posts: 6
Re: Clipboard object in VBScript
« Reply #9 on: October 09, 2009, 05:12:12 am »


Got the solution here:
http://www.geekstogo.com/forum/VBS-Clipboard-t133067.html

Thanks for the help.
Reshmi

Offline Prasanna Hegde

  • Sr. Member
  • ****
  • Posts: 392
    • http://
Re: Clipboard object in VBScript
« Reply #10 on: October 23, 2009, 10:48:12 am »
Hi

If we use the above solution described in this post with IE 8.0

we get security alert as shown in below image

Anyone knows how to disable it in IE 8.0 ? surprisingly.. I did not have this issue on IE 7.0

Offline Tarun Lalwani

  • Administrator
  • Hero Member
  • *****
  • Posts: 3025
    • KnowledgeInbox
Re: Clipboard object in VBScript
« Reply #11 on: October 23, 2009, 10:51:04 am »
This is in security zone settings. Open IE settings and set the zone settings to allow clipboard usage
Regards,
Tarun
KnowledgeInbox Administrator

KnowledgeInbox" style="border:0

Offline Prasanna Hegde

  • Sr. Member
  • ****
  • Posts: 392
    • http://
Re: Clipboard object in VBScript
« Reply #12 on: October 23, 2009, 11:16:39 am »
Thanks Tarun,

yes it works after selecting this option