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

Paste into excel sheet 2

Status
Not open for further replies.

supervi

MIS
Mar 22, 2003
61
0
0
CA
Here is a sample of the code i am using

---------
Dim objexcel As Object
Dim wkbook As Object
Dim sheet As Object

Set objexcel = CreateObject("Excel.Application")
Set wkbook = CreateObject("excel.Workbook")
Set sheet = CreateObject("excel.Worksheet")



wkbook = objexcel.Workbooks.Add

objexcel.Visible = True

sheet.Visible = True

sheet.SetFocus
---------

What this does is open a blank excel sheet.

Know during this time i have information saved onto the clipboard. What i want to do is paste that information automatically when the sheet opens. As of now, after the excel sheet opens i can go to..the edit menu..paste. And all of my information is their.

I thought it would look something like this


wkbook = objexcel.Workbooks.Add

objexcel.Visible = True

sheet.Visible = True

sheet.SetFocus

DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70

But that doesnt work. Any help would be appreciated
 
The worksheet has a Paste method which you should be able to use.

Sheet.Paste Destination:=Sheet.Range("D1:D5")

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
It doesn't seem to be working.
I did some tinkering with the code and this gives me the same result

Where would i put that line of code?

Dim objexcel As Object
Dim wkbook As Object


Set objexcel = CreateObject("Excel.Application")
Set wkbook = CreateObject("excel.Workbook")




wkbook = objexcel.Workbooks.Add

objexcel.Visible = True


objexcel.Paste Destination:=objexcel.Range("D1:D5")



What am i doing wrong?



 
Hard to say given what is shown. First thing is to make sure that your using the Paste method of the worksheet object, not the application or workbook object.

Whatever you're pasting into Excel must match in terms of rows and columns just as it would in a normal Copy/Paste operation. You could try in your desintation setting only identifying the starting cell

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
This is exactly what I have

Dim objexcel As Object
Dim wkbook As Object
Dim sheet1 As Object


Set objexcel = CreateObject("Excel.Application")
Set wkbook = CreateObject("excel.Workbook")
Set sheet1 = CreateObject("excel.Worksheet")



sheet1 = objexcel.workbooks.Add

objexcel.Visible = True
sheet1.Visible = True


sheet1.Paste Destination:=sheet1


I dont know how big my range is going to be. Unfortunately this still doesn't work. But when i go to edit paste then my information appears
 
You do have to specify where you want the information pasted.

If you want the data pasted starting at a specific cell, then you would do the following:
sheet1.Paste Destination:=sheet1.Range("D1")

If you want the information pasted at the currently selected cell, then the following should work, provided that some cell has been selected.
sheet1.Paste

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I'm not a coder... but you state you have the data already in the clipboard and you have code that opens the excel workbook. Instead of coding, click in cell A1 of the workbook and <ctrl> V. That pastes the data... Sorry, to me this is the easiest.
 
Tigger thats exactly what i want to have happen. But i dont want to users of the database to have to hit control v.

I tried both of those maethods cajun but none of them work. I don't think that my excel worksheet

Set sheet1 = CreateObject("excel.Worksheet")

is right.

Hmm
 
Hi!

Regarding the excel objects, perhaps try:

[tt]Dim objexcel As Object
Dim wkbook As Object
Dim wsheet As Object

Set objexcel = CreateObject("Excel.Application")
Set wkbook = objexcel.Workbooks.Add
Set wsheet = wkbook.Worksheets("Sheet1")

objexcel.Visible = True
wsheet.paste destination:=wsheet.range("A1")[/tt]

Roy-Vidar
 
Good catch RoyVidar - I was focused on the .Paste method with the right object, that I missed the proper object initialization.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top