Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem converting VBA to VB 6.0

Status
Not open for further replies.

johnmtb

Programmer
Jul 12, 2008
37
US
I wrote a number of programmes in VBA, which read and wrote to other MS programmes, without any problems.

However, I was asked to produce stand alone programmes, and purchased Visual Basic 6.0 Professional Edition.

I rewrote all of the programmes, and some have not given any trouble, but others have not worked out the way I want them to. Could you please help me?

The first problem is with a programme that reads from MS Word documents (originally this was written in VBA Word), copies one of the documents, which includes a table, opens an Outlook Template file, and pastes the copied material into an e-mail body.

Below is a portion of the code, but this code does not copy the table, just text. If I comment out ‘OutlookFile.Body = WordObj.Selection, and then hit paste in Outlook, it correctly pastes the text and table.

I only need to know how to tell my programme to Ctrl V, or equivalent.

Below is the relevant code at present.

WordObj.Selection.HomeKey Unit:=wdStory
WordObj.Selection.MoveDown Unit:=wdLine, Count:=32, Extend:=wdExtend
WordObj.Selection.CopyFormat

Set OutlookObj = CreateObject("Outlook.Application")
Set OutlookFile = OutlookObj.CreateItemFromTemplate("C:\Documents and Settings\hbcw059\Application Data\Microsoft\Templates\ICOO Bidder Approval.oft")
OutlookFile.Display

OutlookFile.Body = WordObj.Selection

Any help woukld be greatly appreciated.

john
 
I don't know the answer but record a macro and looking at the generated code might tell you. I did it and it generated this by hitting Ctrl A to highlight everything and Ctrl V to copy it:

Sub Macro3()
Selection.WholeStory
Selection.PasteAndFormat (wdPasteDefault)
End Sub

Check this link for more information.

 
Shot in the dark, but maybe this:
Code:
OutlookFile.Body = Clipboard.GetText(vbCFRTF)

It's pasting what's in the clipboard as rich text format.

 
TysonLPrice and JoeAtWork, thank you for your help, but it doesn't work. i tried variations of both suggestions, but still could not get it to work.

i am wondering if i could include CTRL V, somehow, that might work.

any suggestions?

regards,

john
 
Andy,

thank you, i tried that but it doesn't work either.

regards,

john
 

Hmmm....

I placed a Command1 and a Text1 on my Form, and on the side I opened a Notepad. When I run my little application, whatever I type in Notepad and copy it (to clipboard) and then click on Command1 in my little app, I get the text from my Notepad to my text1 textbox.

Code for my Command button:
Code:
Private Sub Command1_Click()
Text1.SetFocus
Text1.Text = ""
SendKeys ("^V")
End Sub
Works for me.....


Have fun.

---- Andy
 
Andy,

yes i agree that works for me too, but only for text. it will not include the Word tables, which i need.

regards,

john
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top