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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello everybody, i am new to vba 1

Status
Not open for further replies.

webstony

Technical User
Jan 29, 2001
19
DE
Hello everybody,

i am new to vba, so please be patient. :)
maybe you can help me. i want to open an excel sheet, select a cell (maybe "D2") and copy its value/content. then i want to return to word and paste this value/content.
my vba-script does only work until the value/content of the "D2" should be copied to the clipboard. Also it does not return to word and hangs up!

Sub WrdXl()

Dim ExcApp As Object
Set ExcApp = CreateObject("Excel.Application")
ExcApp.Visible = True
ExcApp.Workbooks.Open "C:\sheet1.xls"
ExcApp.Range("D2").Select
Selection.Copy
Set ExcApp = Nothing
Application.ActiveDocument.Activate
Selection.Paste

End Sub

Thanks in Advance,
Greetings from Germany,
Sebastian :)
 
OK, sorry for that simple questions. I find it out by myself very quikly. must be following code:

Sub WrdXl()

Dim ExcApp As Object
Set ExcApp = CreateObject("Excel.Application")
ExcApp.Visible = True
ExcApp.Workbooks.Open "C:\Mappe1.xls"
ExcApp.Range("D2").Select
ExcApp.Selection.Copy
ExcApp.Application.Quit
Set ExcApp = Nothing
Selection.Paste

End Sub

But 1 question still remains. how can i supress the popup question if i want to save changes ... #-)
 
Use application.displayalerts = false (whilst this is set to false, default responses are chosen)
but remember to set it back to true within your code - this is not done automatically by Excel

Also, you don't have to physically 'select' the cell before copying it.You could replace
ExcApp.Range("D2").Select
ExcApp.Selection.Copy
with
excapp.range("d2").copy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top