I am working with a Custom Ribbon in Power Point, I need to iterate through all tabs and get the ID of them.
The Ribbon contains Tabs added from different projects (C++, C#) as addins and I don't know their IDs.
I am using VBA to handle the events fired from the Ribbon.
How do I do to get the ID from all tabs in the Ribbon using VBA?
Thanks in advance.
The Ribbon is accessed using CommandBars("Ribbon") which returns an IAccessible object. You access tabs by using
AccessibleChildren _
Lib "oleacc.dll" _
(ByVal paccContainer As Object, _
ByVal iChildStart As Long, _
ByVal cChildren As Long, _
rgvarChildren As Variant, _
pcObtained As Long) _
As Long
This will fill an array with a list of all child elements (tabs) which are also IAccessible objects. The ID's you get are strings, and you can iterate through the children of each one to get submenu items and so on.
It's quite complicated, so the best way to get this done would be to work from an example. Lucky for you there is a gleaming example here: http://www.wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.htm
Pore through the code on that one.
Related
Most of us just 'assume' that a file ending in '.docx' is a Word Document.
If I right-click on the file and show properties, then the properties window shows
Microsoft Word Document (.docx)
I want to know whether I can get that information programmatically.
IE, there's a way to declare
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
and use that to find what program is associated with the file.
If there is, WHAT is the call I need to make Windows give me the file type?
I'm back for more help please.
I'm still on the same project as my question a few weeks ago but stuck on another bit.
I have a multiscreen (win 7) set up and am trying to write an application that will start a number of applications and move/resize them in to the correct positions. I'm doing this as a console app in vb.net.
Following the help I received with my last question I can now start up , move , resize, close all the apps I need bar a couple.
Unfortunately I need to run two applications through Citrix.
One is an Excel sheet.
I can find the windows handle for these windows and select them and or close them but MoveWin() or SetWindowPos() doesn't seem to do anything though the title bar of the window I want to move turns blue so I know it is selecting it..
Any assistance would be greatly appreciated.
A section of the code is pasted below. I'm testing this in excel at the moment and I'll port it across to my console app once working...
Thanks...
Public Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const SWP_FRAMECHANGED = &H20 'Fully redraw the window in its new position.
Sub MoveWin()
Dim retval As Long
Dim hwnd As Long
Dim RetWhnd As Long
hwnd = '123456'
retval = SetWindowPos(hwnd, RetWhnd, 0, 0, 600, 400, SWP_FRAMECHANGED) ' Application.hwnd
End Sub
I am not at my home machine, so I cannot confirm this, but I am fairly certain that VB 6 has a tab on the compile dialog (last one perhaps) that has a citrix-related option checkbox. If it's not there, it might be in the project properties.
Just in case this helps someone else. I've contacted the Citrix people and they basically don't know the answer. I at least wanted to know if it was possible. Anyway as far as I can ascertain, the move command doesn't seem to be possible across the Citrix divide. The solution I've come up with is to leave the actual move part of the code in the remotely run app. That is build code in to the apps run through Citrix to look at an ini file on the local machine and receive instructions from it.
This now works great but will only work for apps that either have ability to run a container language or can be wrapped up somehow..
I'm updating an existing application that scans barcodes and is written in VB.net running on windows compact framework 3.5. The scanner is a POCKETPC running windows mobile handheld 6.5. I have a combobox DropDownStyle='DropDown'. I want to programmatically drop down the box.
I have coded the following:
<DllImport("coredll.dll", SetLastError:=True)> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As IntPtr
End Function
Const CB_SHOWDROPDOWN As Int32 = &H14F
SendMessage(cmbVisitoringUnit.Handle, CB_SHOWDROPDOWN, 1, 0)
The return code is 1 but no dropdown takes place. What am I missing?
Based on a lot more testing I have done, let me answer my own question. In order for the dropdown message to the combobox to work the combobox must have focus, so the code must first set focus to the control and then send the message to dropdown. There is another quirk with the combobox. If it is dropped down and it losses focus for any reason the control cancels the dropdown and then destroys the event. This leads to an impression that the program is not responding and the user needs to repeat the action again. The only fix I could come up with is to always cancel the dropdown where possible.
I recently made an app in VB 2010 and in order to make it individual from the .Net Framework, I begun remaking the app in VB 6.0.
I have a button that is supposed to open the Default Email Client and populate the body with the text from a textbox.
In VB 2010 it works like this :
Process.Start("mailto:test#email.com?subject= &body=" & System.Uri.EscapeDataString(Textbox1.Text))
Can you help me find a way to do what the above does in VB 6.0 ?
To do this, use the ShellExecute API:
Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Private Sub myButton_Click()
ShellExecute Me.hWnd, "open", "mailto:test#email.com?subject= &body=" & Textbox1.Text, _
vbNullString, vbNullString, 1
End Sub
If you want escape your TextBox1.Text, check this question.
VB6 specific
Shell Function
Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.
Syntax
Shell(pathname[,windowstyle])
The Shell function syntax has these named arguments:
Part Description
pathname Required; Variant (String). Name of the program to execute and any required arguments or command-line switches; may include directory or folder and drive.
windowstyle Optional. Variant (Integer) corresponding to the style of the window in which the program is to be run. If windowstyle is omitted, the program is started minimized with focus.
The windowstyle named argument has these values:
Constant Value Description
vbHide 0 Window is hidden and focus is passed to the hidden window.
vbNormalFocus 1 Window has focus and is restored to its original size and position.
vbMinimizedFocus 2 Window is displayed as an icon with focus.
vbMaximizedFocus 3 Window is maximized with focus.
vbNormalNoFocus 4 Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus 6 Window is displayed as an icon. The currently active window remains active.
Remarks
If the Shell function successfully executes the named file, it returns the task ID of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.
Note By default, the Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.
I have a list of URLs to .gif files in an Excel sheet. I want to use VBA to query these websites and insert these images into the same worksheet. I am using Excel 2007.
I tried using the 'Get External Data - From Web' feature to query the website, but it returned the following error:
"Unable to open http://.../blah.GIF. The Internet site cannot return the object you request. (HTTP/1.0 403)"
Is this because Excel cannot import online images with this feature? Or is this problem specifically related to the website?
And most importantly, is there some other way to do this entirely in VBA?
Yes, you can do so. It is actually quite easy. Excel has a AddPicture function. From Excel VBA Help:
expression.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
Use like this:
Sheets(1).Shapes.AddPicture "http://www.mywebsite.com/images/map.gif" _
, msoFalse, msoTrue, 100, 100, 500, 600
Left, Top, Width, & Height are all required and in points.
First you'll want to download the image. There are several methods for doing this. I use the URLDownloadToFile API.
Use the URLDownloadToFile API function to download a file from a URL into a file*:
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
(*visit link for full code)
Then a code sample like this will import them onto the worksheet wherever you like:
From Insert pictures using VBA in Microsoft Excel*:
Sub TestInsertPicture()
InsertPicture "C:\FolderName\PictureFileName.gif", _
Range("D10"), True, True
End Sub
(*visit link for full code)
To be fair to the original authors, I won't repost the code in its entirety here. Apologies for a mostly link-based answer.