Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a project with the following components/ events:
1. create a VB ribbon
add forms to buttons on the ribbon.
Open the relevant form when the Ribbon button is clicked.
2. Added an excel spreadsheet from my local computer in the same project.

I managed to open the forms from the ribbon and now want to add a procedure o the form load event that will activate the relevant worksheet so that the user can see details that currently exist in the worksheet (to add users into a table).

Any assistance would be greatly appreciated.

What I have tried:

RIBBON CODE:
Imports ExcelApplication
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Tools.Ribbon

Public Class Ribbon1
    Dim UserForm As frmUserCreate

    Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnAddUser_Click(sender As Object, e As RibbonControlEventArgs) Handles btnAddUser.Click

        UserForm = New frmUserCreate
        UserForm.Show()

    End Sub

USER FORM CODE:
Public Class frmUserCreate
    Private ReadOnly Application As Object
    Dim WrkSht As Users
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Me.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub frmUserCreate_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CType(Application.ActiveWorkbook.Sheets(1), Excel.Worksheet).Select()
    End Sub
Posted
Updated 19-Feb-23 21:43pm
v3
Comments
Dave Kreskowiak 19-Feb-23 13:56pm    
Again, Visual Studio is an editor and debugger, not a language or a framework. It's not Visual Studio you're trying to learn, but VB.NET, C#, and others, as well as various programming frameworks, like .NET, VSTO, ASP.NET, MVC, WPF, Windows Forms, ...

Stop tagging your questions as "Visual Studio". Better tags would be "VB.NET" and "Office Interop".
Leslie Gombart 20-Feb-23 5:00am    
Sorry... didn't understand your message first time! Now I understand & will do so

1 solution

You first need to open the Workbook to get access to the individual shhets. See Excel Object model overview - Visual Studio (Windows) | Microsoft Learn[^].
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900