Display read only excel worksheet in vb6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michels287
    New Member
    • Mar 2008
    • 20

    Display read only excel worksheet in vb6

    Hello...

    I am using VB 6 and wish to have a form that displays a read only worksheet from my excel file:

    C:\Users\Chris\ Desktop\myexcel .xlsx

    Anyone have any ideas how to display the first sheet on the form in VB6 with the click of a button?
  • michels287
    New Member
    • Mar 2008
    • 20

    #2
    I would like the excel sheet to be displayed on the form. I will code it so that once the Open Excel button is pressed, it will move the label to excel cells, save the changes, close it immediately and display the resulting excel sheet on my form.

    Any ideas how to display the excel sheet on a visual basic form? I am doing this because I do not want the user to be able to manipulate my excel spreadsheet to mess up the format, formulas, etc.

    The OLE seems like it would work perfectly. I have been trying to use an OLE from the original file.

    However, when the new information is sent to Excel, the OLE does not update itself with the newest information for the relevant Excel sheet.

    I have the OLE Enabled property set to False, so the user cannot manipulate the sheet.

    The source doc for the OLE property is also set to the excel file I have the VB information sent to.

    And I have update options in the OLE property set to Automatic, thinking that would constantly update the OLE Excel sheet once new data is sent to the source doc.

    When I press the button to send my VB info to the excel sheet it DOES open the excel sheet, send the info appropriately, save it to the same Excel sheet, and close it without the user seeing any of the operation. It's just when the form loads with the OLE for that sheet do I see that it NEVER updates it.

    That button's code that opens, sends, saves, and closes the Excel sheet... I declared my variables in the General Declarations:

    Option Explicit

    Dim oXLApp As Excel.Applicati on
    Dim oXLBook As Excel.Workbook
    Dim oXLSheet As Excel.Worksheet

    Set oXLApp = New Excel.Applicati on
    Set oXLBook = oXLApp.Workbook s.Open _("C:\Users\Chr is\Desktop\myex cel.xlsx")
    Set oXLSheet = oXLBook.Workshe ets(1)
    oXLApp.Visible = False


    Dim my_variable As String
    my_variable = Label1(0).Capti on
    oXLSheet.Cells( 3, 2).Value = my_variable

    Set oXLSheet = Nothing
    oXLBook.Close SaveChanges:=Tr ue
    Set oXLBook = Nothing
    oXLApp.Quit
    Set oXLApp = Nothing

    Load Form2
    Form2.Show ' --- Form2 should display the update OLE for the Excel sheet

    When I inserted the OLE of the excel file, I also clicked the "Link" button to show the copy of the excel sheet. But it never displays the updated Excel sheet.

    Comment

    Working...