LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default Hosting Excel in a WinForms application

Hi Vincent,
amusing idea; why not in a userform ?
You can try in a userform module:

Option Explicit
Private Declare Function FindWindowA& Lib _
"user32" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function SetParent& Lib _
"user32" (ByVal hWndChild&, ByVal hWndNewParent&)
Private Declare Function SetWindowLongA& Lib _
"user32" (ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function MoveWindow& Lib _
"user32" (ByVal hwnd&, ByVal x&, ByVal y& _
, ByVal nWidth&, ByVal nHeight&, ByVal bRepaint&)

Private WithEvents oXL As Excel.Application
Private xlHwnd&, hwnd&

Private Sub UserForm_Activate()
DoEvents
oXL.Visible = True
SetParent xlHwnd, hwnd
SetWindowLongA xlHwnd, -16, &H140F0000
Call UserForm_Resize
oXL.Workbooks.Add
End Sub

Private Sub UserForm_Initialize()
Me.StartUpPosition = 3
hwnd = FindWindowA(vbNullString, Me.Caption)
SetWindowLongA hwnd, -16, &H84CC0080
Dim c As Object
Set oXL = New Excel.Application
oXL.Caption = "IsMine"
' Without CommandBars.
'For Each c In oXL.CommandBars
'If Not c.Name = "Cell" Then c.Enabled = False
'Next
xlHwnd = FindWindowA(vbNullString, "IsMine")
End Sub

Private Sub UserForm_QueryClose(Cancel%, CloseMode%)
On Error Resume Next
SetParent xlHwnd, 0
oXL.Visible = False
DoEvents
Me.Hide
DoEvents
Dim c As Object
For Each c In oXL.CommandBars
c.Enabled = True
Next
oXL.Quit
Set oXL = Nothing
End Sub

Private Sub UserForm_Resize()
Dim w!: w = Me.InsideWidth * 4 / 3
Dim h!: h = Me.InsideHeight * 4 / 3
MoveWindow xlHwnd, 0, 0, w, h, 1
End Sub

Regards,
MP

"Vincent Melia" a écrit dans le
message de news: ...
Is there a way to directly embed it in a Winform? It would also be great

to
have the embedded Excel docs toolbars to merge with the Winforms toolbars
when activated.

I've tried a WebBrowser control but working with it was kludgy and

obscure.

Any ideas?

""Peter Huang" [MSFT]" wrote:

Hi

From the OWC document, the spreadsheet did not have inside print. It is
printed when it is hosted in a web page. I think that is why it is

called
Office Web Component. :)

Print a spreadsheet
To print a spreadsheet on a Web page, you must print the entire Web

page.
¡¤ To print a spreadsheet from a design window, see Help in your
design program for specific instructions about printing a Web page.
¡¤ To print a spreadsheet from the browser, click Print on the
Microsoft Internet Explorer File menu.
Note If the spreadsheet is wider or longer than the printed page, the
areas that don't fit on the page are not printed. For more control over

how
the data is printed, including the ability to print a long list and set
page breaks, you can export the spreadsheet to Microsoft Excel by

clicking
Export to Microsoft Excel on the toolbar. For information about printing
from Excel, see Excel Help.

For your scenario, I think it is better to export the spreadsheet in xls
file and then print via Excel automation.

If you still have any concern, please feel free to post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no

rights.






 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Hosting, Reseller Hosting, and Dedicated Hosting!!!!!! ufi02 Excel Worksheet Functions 0 March 27th 09 07:22 PM
Display of Excel file in Winforms in Smart Device Application Bhavesh Mandaliya[_2_] Excel Discussion (Misc queries) 0 October 20th 08 10:10 AM
How can i display excel file in winforms in Smart Device Applicat Bhavesh Mandaliya Excel Discussion (Misc queries) 0 October 20th 08 07:11 AM
new hosting for me [email protected] Excel Discussion (Misc queries) 0 April 9th 05 12:29 AM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM


All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"