Access 2016 I can't see Access Class Objects in VBE - vba

I created tables and forms in Access 2016. When I Alt-F11 to VBE they do not show up. How do get them to show?

Tables shouldn't be visible in the VBE at all. So that's expected. Only objects that have a VBA module are shown in the VBE.
Forms are only shown in the VBE if they have a module. Add a module to a form by opening it in design view, and either choosing View Code on the Design tab of the ribbon, setting the Has Module property to Yes, or by adding code to one of the events.

Related

How do you add a 'public partial class ThisWorkbook' to a VSTO application in C#?

I am trying to add an ActionPane to an Excel VSTO Add-in. I need to access the ThisWorkbook.ActionsPane collection to add my action panes.
The Microsoft documentation at:
https://learn.microsoft.com/en-us/visualstudio/vsto/how-to-add-an-actions-pane-to-word-documents-or-excel-workbooks?view=vs-2019
says:
To show the actions pane, add the user control to the Controls
property of the ThisDocument.ActionsPane field (Word) or
ThisWorkbook.ActionsPane field (Excel).
Add the following code to the ThisDocument or ThisWorkbook class as a
class-level declaration (do not add this code to a method).
This implies that I need to add a ThisWorkbook class to the VSTO solution. My questions are:
What base class contains the ActionsPlane collection?
How would I add a class derived from this base class to my VSTO?
Some on-line examples of a ThisWorkbook class contain regions that are designer generated.
My workload includes every VSTO item available. There are no Excel items at all under 'Add New Item' or 'Add New User Control' in Visual Studio 2019. Beyond the Ribbon Bar, there are no designers for VSTO.
The only way that I see to do this is to add a ThisWorkbook class manually.
Am I correct in saying that any designers that may have existed in previous versions of Visual Studio, no longer exist in Visual Studio 2019?
You need to differentiate document-level and application-level add-ins.
An actions pane is a customizable Document Actions task pane that is attached to a specific Microsoft Office Word document or Microsoft Office Excel workbook. The actions pane is hosted inside the Office task pane along with other built-in task panes, such as the XML Source task pane in Excel or the Styles and Formatting task pane in Word. You can use Windows Forms controls or WPF controls to design the actions pane user interface.
Read more about Actions panes in the How to: Add an Actions Pane to Word Documents or Excel Workbooks article if you are developing a document-level add-in.
If you are developing an application-level add-in you may be interested in using Custom task panes. Task panes are user interface panels that are typically docked to one side of a window in a Microsoft Office application. Custom task panes give you a way to create your own task pane and provide users with a familiar interface to access your solution's features. For example, the interface can contain controls that run code to modify documents or display data from a data source. See Walkthrough: Automate an application from a custom task pane to get started quickly.

How to instantiate a UserControl using VB?

So in C# to declare and instantiate a UserControl, you would go about it similar to this:
UserControl1 userCont = new UserControl1();
userCont.Show();
And this would show your user control named UserControl1.
This is the way you do it in C#, now how do you do this in VB?
Because I have coded an Excel Add In, and have put a userControl in the ribbon, but it does not want to show, and that project is in VB, not C#.
EDIT:
Some explanation of my project:
I have an Excel 2013 and 2016 VSTO add-in project type.
I have 3 classes, namely:
UserControl1.vb - as my userControl
Ribbon.vb - as my ribbon class
ThisAddIn.vb - as the add in class
My userControl is rather simple, it has 3 buttons, a "Yes" button, a "No" button, and an "Add Tables" button. It has 1 listBox, and 12 checkboxes...
The Ribbon is also quite simple, I have 2 buttons in the Ribbon called "Show" and "Loop"...
The ThisAddIn class contains code that will make this add in work, such as methods and general functionality...
Okay so that's my classes...
The goal of my project is:
When the "Show" button is clicked, a CustomTaskPane will appear in excel on the right, inside this customTaskPane will be my userControl...
(This works)
Big thanks to DrDonut for his answer
When the "Add Tables" button is clicked (in the userControl), I want excel to iterate through all the sheets, and add every listObject's name (tables name) to the listBox.
(The Loop and Add Tables button are the same)
In C# I know you go:
this.ListBox1.Items.Add("Item 1");
And that will add an item to the listbox, the same principle is applied in VB, but with my ListBox sitting in my userControl which inherently sits in the CustomTaskPane, no items can seem to be added...
(Adding items to the list box does not work)
And with regards to the looping of tables, or retrieving their names, this doesn't work either...
(This is what I really want to get going nicely)
Hope this edit will shed some clarity on the situation...
Some gritty information:
OS: Windows 10 Pro (x64)
RAM: 32gb
CPU: i7-6700 #3.40ghz
Microsoft Visual Studio Community 2015
Microsoft Excel 2016 (x64)
In vb.net it's quite similar, for a task pan (the panel at the right side of an office application) it is:
Dim userControl as UserControl
Dim userTaskPane as Microsoft.office.tools.CustomTaskPane
userControl = new UserControl
userTaskPane = Me.CustomTaskPanes.Add(userControl, "Title")
userTaskPane.visible = true
Now it should show the panel.
Edit: Source: https://msdn.microsoft.com/en-us/library/aa942846.aspx
Edit 2: You also need to set the right references. Assuming that you use visual studio, go to the solution explorer -> Your project -> References. In my project these contain the following:
Microsoft.Office.Interop.Excel
Microsoft.Office.Tools
Microsoft.Office.Tools.Common
Microsoft.Office.tools.Common.v4.0.Utilities
Microsoft.Office.Tools.Excel
Microsoft.Office.Tools.v4.0.Framework
Microsoft.VisualStudio.Tools.Applications.Runtime
Office
I don't know if you need all of them, but for sure you will need some of them.

main.vb, main.designer.vb and missing Form Designer

I have been working with "visual basic.net" on a "windows forms" application. While manipulating controls and adding event handlers I noticed the resultant code was being generated within a file named 'main.designer.vb'. However, if I look in the solution explorer for my project there is no 'main.designer.vb' file, just 'main.vb'.
This is not a colossal problem as it runs properly. However, having closed the 'form designer' window I now cannot reopen it! 'main.vb' has no option to 'view in form designer'.
Any advice on this?
Would it be possible to copy the contents of 'main.designer.vb' in to 'main.vb' and delete 'main.designer.vb' entirely? If I did this, the next time I manipulated the form would the code be added to 'main.vb' or would a new 'main.designer.vb' be created?
I seem to have sorted out the problem.
'main.vb' was completely empty. All the code I had generated and written directly was inside 'main.designer.vb'. However, once I made a class definition within 'main.vb':
Public Class main
End Class
and then cut/pasted all my custom event handler code and subroutines from 'main.designer.vb' to THAT class - all was well. 'main.vb' now shows the correct form icon and FINALLY offers the correct 'view designer' context menu option.
I am not sure why it happened in the first place though.
Look in the Solution Explorer in Visual Studio. In the toolbar in this window is a button called "Show all files". Click it.
Then every file in the projects folder is actually shown in the solution explorer. Expand the treenodes for the form and you will see the designer.vb.
There are also buttons for switching between code-view and designer view. Just remember to select the form in the solution explorer for the buttons to show the correct form in the designer.

Excel VBA: How to turn code into a full on toolbar tool? [duplicate]

I am in the process of creating a VBA add-in for Excel 2010, and I used the "Custom UI Editor for Microsoft Office" tool to create my own ribbon.
However, I would like to give the user the option to load my add-in without displaying the ribbon, or with different parts of the ribbon visible.
With menus, I know you can completely control them programmatically, but ribbons seem to work differently.
Is there a way in VBA to not load my customUI.xml ribbon tabs on startup?
Is there a way to remove items from (or add items to) these tabs at runtime?
here is a whole slew of help on this subject Awesome Ribbon Help. I think points 2 and 3 are of particular interest to you.

Refreshing the ribbon interface after a call from a macro in an excel sheet

Here is my scenario:
I have an old excel project with macros that I've imported in a vsto project.
I have designed a custom ribbon (startFromScratch = true) to make it look like a dictator application.
I still want to use the existing macro code since it would take too much time to translate all the vba code in c# code
I have a class that is marked with the [ComVisible(true)] attribute so that I can call vsto methods from the vba code.
The problem is that I can't hide tabs, I can't get the ribbon to refresh. I can change the state of other controls (e.g. set checked state for CheckBox), but I can't hide or disable my custom tabs.
I have tried PerformLayout(), PerformDynamicLayout() on the ribbon, ribbon.RibbonUI.Invalidate(), but nothing works, the tab never changes state, although in code I set its visible property to false.
What do I need to do in order to refresh the ribbon at runtime?
Edit:
I just tried the same thing by exporting the ribbon to xml and the Invalidate() method works as expected. Is there any way to accomplish this for a ribbon designed with the visual editor?
I've replicated your problem when I set the StartFromScratch property of the ribbon to True, but it goes away when I set it to False. This is confirmed by MSDN.
You cannot change the visibility of custom tabs at run time if this property is set to true.
As a workaround, set StartFromScratch to False, add in a tab for each default tab, setting the ControlIdType of each to Office and the OfficeId of each to their default name (TabHome, TabFormulas, etc.), then set each of these built-in tab's visibility to False. (MSDN has made available a full list of control IDs for their Office apps for easy reference.)