Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 How to Write Clipboard Data (Text, Image, Formats) from Word into a Variable?

$
0
0
Hello community,

I'm a little bit in despair because the German forums couldn't help me, excuse my English.

First of all, I didn't use VB for 6 years, so I would say I'm a complete newbie by now and I start from scratch.

I'm currently programming an application that dynamically creates a Word-file.
It reads the text written by the user into a Word-template (including an image and 2 tables), which content is then copied as a whole and should then be pasted into that new Word file.

Then the program manipulates an Excel table according to the choices the user made in the application and then copies the table (page by page) and pastes it into the new Word file formatted as image after altering the page-align to landscape.

The problem is:
I CAN copy and paste directly from the clipboard but what I need to do is to save the clipboard content in some variables.

First of all because I don't want the users to lose their clipboard content, so the program should save the current clipboard to a variable and should restore it after it is finished with the copying and pasting.
But I need it for other stuff, too:
E.g. the content of the manipulated Word-templated should be copied into the variable "startpage" and every page of the Excel-file (there are 2) should be copied into another variable (excelpage1 and excelpage2)

I played around with DataObject, and I'm able to save and read the text via Clipboard.GetText and Clipboard.SetText, but then it's unformatted.

So this works:
Code:

Public clipboardfromword As New DataObject

' Some Code
word.Range.WholeStory()
word.Copy()
clipboardfromword.SetText(Clipboard.GetText)
Clipboard.Clear()

'Some Code

Clipboard.SetText(clipboardfromword.GetText)

But as I said, this is just Text. I tried DataObject but that returns an Error and causes a COM-exception.

Any Ideas how I could read the raw data from the clipboard into variables and put it back into the clipboard when I wish to?

Greetings

Broco

Viewing all articles
Browse latest Browse all 27554

Trending Articles