INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...I am so glad that I found your site, it is an excellent resource and has helped me greatly..."

Geography

Where in the world do Tek-Tips members come from?

 Copying cells from excel spreadsheet to axspreadsheet

fawkes (TechnicalUser)
16 Sep 04 10:31
I'm creating an application where I intend to add an axspreadsheet object (excel office web component) to my form.

We have a number of excel spreadsheets that various people create and maintain but I want to make them accessible with added functionality gained by a bespoke application.

What I want to do is copy the contents of a spreadsheet, formulae, values, etc. from the excel spreadsheet object to the axspreadsheet object.

I can run a loop to add the contents of each cell in the excel spreadsheet to the respecive cell in the axspreadsheet and I can start the copy procedure in the excel spreadsheet then manually select the cell in the axspreadsheet and, using the paste command from the pop-up menu, paste the contents into the axspreadsheet.

So how do I perform the paste using code?

Any ideas?
fawkes (TechnicalUser)
17 Sep 04 3:40
Any ideas?
fawkes (TechnicalUser)
17 Sep 04 3:48
What a plank!! My code wasn't complete enough.

This works

CODE


        'Declare new excel and worksheet objects
        Dim objExcel As New Excel.ApplicationClass
        Dim objSheet As Excel.Worksheet
        Try
            'Create and open the correct excel workbook
            objExcel = CreateObject("Excel.Application")
            objExcel.Workbooks.Open("C:\Book1.xls")
            objExcel.Visible = True
            objExcel.Parent.Windows(1).Visible = True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Select all the cells in the relevant worksheet
        'and copy the contents
        objSheet = objExcel.ActiveSheet
        objSheet.Cells.Select()
        objSheet.Cells.Copy()

        'Select a cell in the AxSpreadsheet control that is
        'already declared and initialised in the class
        Me.AxSpreadsheet1.Cells(2, 2).Select()

        'Paste the contents
        Me.AxSpreadsheet1.Cells(2, 2).Paste()

Taking a fresh look in the morning certainly helps.

Fawkes
fawkes (TechnicalUser)
17 Sep 04 3:53
I've hit a secondary problem.

I've added the following code to the end:

CODE

        objExcel.Quit()
        objExcel = Nothing
        GC.Collect()

The problem is that I keep getting a message asking if I want to save data on the clipboard, how do I stop this?
fawkes (TechnicalUser)
17 Sep 04 5:49
I've found another couple of problems with my method.

1. It doesn't copy any objects (images, etc.)
2. It doesn't copy cell properties like protection or column width.

Any ideas on this at all?
russellmunday (TechnicalUser)
15 Mar 05 6:14
I cant see where you have saved the sheet in your code but if you have you need to add the line :objsheet.saved = true
before your :objexcel.quit line

What reference have you added?

Start A New Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Promoting, selling, recruiting and student posting
are not allowed in the forums.
Posting Policies

LINK TO THIS FORUM!
(Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum)
TITLE: Visual Basic(Microsoft) -VB.NET 2002-2008 Forum at Tek-Tips
URL: http://www.tek-tips.com/threadminder.cfm?pid=796
DESCRIPTION: Visual Basic(Microsoft) -VB.NET 2002-2008 technical support forum and mutual help system for computer professionals. Selling and recruiting forbidden.