Copy and Paste to Excel from another program

I use vb script to paste data to Excel that has been copied to the clipboard via SAS code. However, my code has now failed for some users. SAS accomplishes the writing to the clipboard task, and then creates and issues a system command to run the VB script.
Here is an example of the current VB script:
Dim objExcel
Dim Newbook
Dim NewSheet
Dim inSheetCount
Set objExcel = CreateObject("Excel.Application")
Set Newbook = objExcel.Workbooks.Add()
objExcel.Visible = True
inSheetCount = Newbook.Application.Worksheets.Count
set NewSheet = Newbook.Sheets.Add( ,objExcel.WorkSheets(inSheetCount))
objExcel.DisplayAlerts = False
i = inSheetCount
Do Until i = 0
 Newbook.Worksheets(i).Delete
 i = i - 1
 Loop
Newbook.Sheets(1).Name="N1"
Newbook.Sheets("N1").Select
Newbook.Sheets("N1").Range("A2").Activate
NewBook.Sheets("N1").Range("A2").PasteSpecial
NewSheet.SaveAs("c:\temp\test\tclass1.xlsx")
objExcel.Workbooks.Close
objExcel.DisplayAlerts = True
objExcel.Quit
The problem is that for some users, Excel can't access the clipboard unless it is already open before the copy operation occurs.
How can I convert the above script into multiple scripts that allow me to use SAS to: (1) open Excel; (2) not part of script: accomplish the copy operation via SAS; (3) perform the paste and save operation in Excel and then close Excel?
TIA,
Art 

Your link wasn't there when I originally read your post, so I figured out a way to solve my problem on my own. However, thank you for your help and I will definitely look at the link you provided.
Regardless of the fact that the following is probably quite sloppy code, I was able to do what I wanted by incorporating running Notepad as a shell within my vbscript. The code simply does everything that my original example does but, just prior to pasting
from the clipboard, opens the txt file in notepad and copies it to the clipboard:
Dim objExcel
Dim Newbook
Dim NewSheet
Dim inSheetCount
Set objExcel = CreateObject("Excel.Application")
Set Newbook = objExcel.Workbooks.Add()
objExcel.Visible = True
inSheetCount = Newbook.Application.Worksheets.Count
set NewSheet = Newbook.Sheets.Add( ,objExcel.WorkSheets(inSheetCount))
objExcel.DisplayAlerts = False
i = inSheetCount
Do Until i = 0
 Newbook.Worksheets(i).Delete
 i = i - 1
 Loop
Newbook.Sheets(1).Name="test"
Newbook.Sheets("test").Select
Newbook.Sheets("test").Range("A1").Activate
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad.exe c:\temp\test\clip.txt"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "%E"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "A"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "%E"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "C"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "%F"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "X"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "{TAB}"
WScript.Sleep 500
objShell.SendKeys "{ENTER}"
Wscript.Sleep 1000
Newbook.Sheets("test").Paste
NewSheet.SaveAs("c:\temp\test\server_formatted.xlsx")
objExcel.Workbooks.Close
objExcel.DisplayAlerts = True
objExcel.Quit
WScript.Quit
Arthur Tabachneck

Similar Messages

  • How can i copy and paste an image from 1page to another on iPad

    i have been trying all afternoon to get copy and past to work on images from 1 page to another, are shortly going on holiday and thought i would keep in contact with a website that i belong to, to be able to go on the forum and take part in the quiz's that i do now, but are not able to copy and paste an image from 1 page to another, i click on the pic, save image and copy comes up,i press copy, then go the the other page,click on the box, paste comes up but no image what am i doing wrong
    any help would be most appreciated as i have been trying for the last 4 hours
    margaret

    Copy and paste? What app are you using?
    When you tap on an image and select copy that usually copies the URL of the image.
    Save image copies the image to your Camera Roll.
    Most apps have an Insert choice that inserts an image from your Camera Roll into the document you are working on.
    But if you tell us which app you are using, we should be able to provide more exact info on how to get done what you want.

  • Unable to copy and paste a phote from my photo library to another photo album

    iphoto 6.0.6 unable to copy and paste a photo from my main library album to another photo album.  why does the copy and paste function not work for these albums.  I have tried to drag it and drop it into the album, but nothing works.  it this a bug?  When I created the album several years ago, I was able to copy and paste photos into it, but now when I try to copy and paste nothing happens.  Again I ask, is this a bug?

    Try also posting here:
    iPhoto for Mac

  • Problems copying and pasting multiple slides from one captivate to another.

    I have been able to copy and paste several slides into
    another captivate and suddenly this has stopped working. I am using
    the ctrl key to select multiple slides (a set of 3) and the using
    the Edit drop-down to select copy slide. Then, I click on the other
    captivate and click paste slides. It is only bringing 1 slide, the
    first one, and not the 2nd and 3rd... any ideas. I've had another
    set of eyes look over my shoulder... and we're both scratching our
    heads.
    Also, for some reason the text entry boxes are being copied,
    but the failure caption associated with it does not come along. It
    also copied the button but lost the association with the text entry
    box. WTH?

    This might work, this might not. I have copy paste problems
    on a regular basis and all that works for me is closing Captivate
    down and then re open and continue. At worst, a reboot tends to
    solve this glitch in my experience.
    Good Luck

  • How do you copy and paste a photo from the internet without a mouse?

    Does anyone know how to copy and paste a photo from the internet without a mouse?  I would appreciate a response asap.  Thanks.

    http://support.apple.com/kb/HT2477
    Pointing, clicking, and getting around
    When you move your mouse or finger on a trackpad, you control a pointer (also known as a cursor) that moves across your screen. The pointer allows you to select and interact with the various items on your screen, including selecting files, clicking buttons, dragging sliders, and so on. Sometimes the pointer may look like a hand, a crosshair, an I-beam, or another icon, depending on what you're doing and the application you're using.
    For example, if you're using Safari to view this webpage and move the pointer across it, notice that it turns into an I-beam when you move it over text or a text field. When you see this, you can usually interact with the text or field below it. When you move the pointer over a button or link, the pointer turns into a hand, letting you know that you can click on the item.
    Depending on what you're doing and what application you're using, your pointer (far left) may change appearances
    Clicking your mouse button or trackpad button once allows you to select the item that your pointer is on. In other words, if your pointer is on a file's icon, clicking once will select it. If the pointer is on a button or link, clicking once will activate it. If your pointer is on a text field, clicking once highlights the field and allows you to start typing text in it.
    If you want to open a file, folder, or application, click your mouse button or trackpad twice. This is known as double-clicking. In general, you'll need to double-click items if you want to open them from a Finder window or the desktop. The exception to this is opening stuff from the Dock—just click once on an icon in the Dock to open it.

  • How to copy and paste the graphics from illustrator to MS word. What I tried is exporting in png with highest resolution and then inserting in to word. This loses a bit of resolution in comparison to direct copy and paste as EMF.  But if I do a copy and p

    How to copy and paste the graphics from illustrator to MS word. What I tried is exporting in png with highest resolution and then inserting in to word. This loses a bit of resolution in comparison to direct copy and paste as EMF.  But if I do a copy and paste, and then take a print of the document, all the graphs and text is printed upside down, flipped back.

    Use the Pencil Tool
    alex
    adrian stock wrote:
    > How to copy and paste a single pixel
    >
    > I want to copy a single pixel and then paste it in the
    position of
    > another pixel in the same image.
    >
    > (This is in effect changing the colour of the target
    pixel, isn't it.
    > But in my case copying an existing pixel seems simpler
    than selecting a
    > colour from the swatch or using the colour picker.)
    >
    > What is the most efficient way of doing this?
    >
    > I tried to select one pixel with the marquee tool. Then
    copied it with
    > control-C, but then how do I select the target pixel and
    paste with
    > control-V?
    >
    > Thanks for your help.
    >
    > Adrian
    >

  • Is there a way that you can copy and paste blade effects from one clip to the other so that the cuts are an exact duplicate of each other?

    Is there a way that you can copy and paste blade effects from one clip to the other so that the cuts are an exact duplicate of each other?

    The same cuts that I have in this clip that i performed with the blade tool, I want to duplicate, copye, paste and apply to another clip. I want the cuts to mimic and be an exact same. I wish i could highlight the clip, click copy and then highlight the other clip and then click paste and the cuts apply.

  • I want to copy and past 58 links from my IE favorites into the bookmarks toolbar...not one at a time. where's the folder i can copy these too?

    i want to copy and past 58 links from my IE favorites into the bookmarks toolbar...not one at a time. where's the folder i can copy these too?
    == This happened ==
    Not sure how often
    == i want to copy and past 58 links from my IE favorites into the bookmarks toolbar...not one at a time. where's the folder i can copy these too?

    Firefox doesn't store the bookmarks as separate files in a folder, but uses a sqlite database file with the name places.sqlite.
    You will have to export those favorites in IE to an HTML file and import that file in Firefox.
    Bookmarks > Organize Bookmarks > Import & Backup > Import HTML : "From File"
    See http://kb.mozillazine.org/Backing_up_and_restoring_bookmarks_-_Firefox

  • I am trying to copy and paste a story from a blog.  I can only view the first page on the Pages app.  How do I see the rest of the pages?

    I am trying to copy and paste a story from a blog.  I can only view the first page on the Pages app.  How do I see the rest of the pages?

    Thank you.  That helped in the first step.  I was able to copy text onto multiple pages.
    Now I can't get the pictures to copy.  How do I get my pictures to copy?
    Also once the blog page is on pages, how do i make changes to it?
    This my story and the page I am trying to copy.
    http://www.city-data.com/forum/tennessee/359683-going-off-grid-east-tennessee.ht ml
    Thanks so much
    Lisa(writing) and Mike trying to get it right.

  • I use classical Hebrew for my work, and Pages will only display English characters even with a Hebrew font selected. If I cut and paste Hebrew characters from another document, as long as the font is supported, it will appear in Pages.  If I type it won't

    I use classical Hebrew for my work, and Pages will only display English characters even with a Hebrew font selected. If I cut and paste Hebrew characters from another document, as long as the font is supported, it will appear in Pages.  If I type it won't continue in Hebrew.  I have tried downloading several fonts, including those from professional societies, but the only way to get Hebrew in my document is to cut and paste.  Does anyone know how to fix this?  I use an older MacBook running OS 10.9.1.  I used to do my Hebrew work in Word, but it is no longer supported by Mac OS.

    Just clarifying:
    Pages '09 has bad support for Hebrew, Arabic etc but will accept pasted text.
    Pages 5 has much better support but with bugs.
    If you have columns they are in the wrong order ie Text starts in the left column and ends in the right column.
    If you type English into Hebrew text it tends to fall in the wrong position eg instead of to the left of Hebrew punctuation it goes to the right.
    As Tom recommends the only real solution on the Mac is Mellel.
    Peter
    btw Tell Apple, they are amazingly slow to fix this running sore which has been broken since RtoL was supposedly introduced in OSX 10.2.3 over a decade ago.
    Peter

  • HT2506 hi i can't seem to copy and paste pdf files from preview to a microsoft word document. it always comes up with nonsense characters in the word document. how do i fix this? thanks in advance

    hi i can't seem to copy and paste pdf files from preview to a microsoft word document. it always comes up with nonsense characters in the word document. how do i fix this? thanks in advance

    Hi,
    The quickest way to do this (tested with OS 10.8.2, MS Word 2011) is in one line:
    tell application "Microsoft Word" to close every document whose name begins with "book"
    The reason why your script doesn't work is that you aren't specifying to Word which document you want it to close.
    So, changing one line ought to do it:
    close document incrementvalue -- instead of "close document"
    But... when you close a document, you change the document count. Document 2 becomes document 1, document 3 becomes document 2 etc. So eventually you'd get a message saying "The object you are trying to access doesn't exist".
    Because of this, if you want to do it in a repeat loop, you have to work backwards:
    tell application "Microsoft Word"
      set doc_count to count documents
      repeat with x from doc_count to 1 by -1
      if name of document x begins with "book" then close document x
      end repeat
    end tell
    Hope this helps.

  • Why can't I copy and paste the music from my iPhone on iTunes 11 to a folder in my Music Library?

    Why can't I copy and paste the music from my iPhone on iTunes 11 to a folder in my Music Library? I want to have a copy of the music on iTunes so when I update to a newer version of iOS I don't lose my music. And no I didn't buy this music off iTunes and neither will I use iTunes Match.

    There has never been a function to copy anything from an iPhone and paste it to a computer.
    All of your media should be in iTunes already.
    If it is not and was purchased from iTunes, right click on the device and select Transfer Purchases.
    If the media is not in iTunes and was not purchased from iTunes, how did you get it on the device in the first place?

  • When I copy and paste a chapter from MS Word into Pages my tables and equations are trashed.  But importing them results in no control over my template How do I get my chapter into my template without copying

    When I copy and paste a chapter from MS Word into Pages my tables and equations are trashed.  But importing them results in no control over my template How do I get my chapter into my template without copying?

    Try just Opening the Word .doc from within Pages and see if that gets closer to what you want, then copy the chapter you want from the Pages version.
    Peter

  • How can I copy and paste table cells from Pages into InDesign with minimum reformating?

    How can I copy and paste table cells from Pages into InDesign with minimum reformating?

    Do you mean you want to retain the formatting from Pages, or retain formatting already applied in ID?

  • How to copy and paste a photo in another folder using Aperture?

    How to copy and paste a photo in another folder using Aperture?

    What do you want to achieve? Do you really want to create a copy of an image, and thus create a second copy of the master image file? You will waste disk space this way.
    Usually you would create new versions of an image, if you want versions with different adjustments. Versions do not require much additional disk space. But all versions of an  image have to be in the same project. To create a new version: Main menu bar -> Photos -> Duplicate Version
    To create a copy of an image in another project (and to waste the space ) drag the image to another project while holding down the option key. This will create a copy in the other project.
    Sofar nobody here could come up with a good reason why one would want to create a copy. I am curious what in your workflow requires you to do that. Would you mind to tell us?
    Regards
    Léonie

Maybe you are looking for