How to check for the active Application? - vba

I made a VBA-Macro, activated via a Ribbon-Button for exporting selected Mails into a certain folder.
I'd like to make this Macro available in Word and Excel (for exporting doc/xls) into the same folder-structure.
Is it possible to check for the active application and then decide if a Mail(s)-Export or a simple Doc/Xls-Export should be done?

If you are working with multiple Applications probably the easiest way to identify one would be to use Application.Name property.
If you happen to have passed an object of some type that has the .Application property you can also call that. Refer to this post for details.
Also, with most MS-Office objects you can go up the hierarchy using the .Parent property to get all the way up to the Application, ie. .someObj.Parent.Parent.Parent.Application.Name

Related

Add custom control to toolbox and have its properties show up in the properties window

To illustrate what I'm asking, let's say I have a custom TextBox that has 2 modes. Mode 1 only allows numbers, and mode 2 only allows dates in a particular format.
Using a class module I can create this custom TextBox, and I can use a loop when the userform initialises to set which TextBoxes are custom.
What I'd like to happen is have the custom TextBox, or what ever custom control I want, show up in the toolbox. And I also want its custom properties, if they exist, to show up in the property window.
So far, I've been unable to find a way to do this. In fact, I've been unable to find out if it's even possible. It seems, to me anyway, that it's something that should be possible, but maybe I'm barking up the wrong tree. If it's possible I'd really appreciate being pointed to a resource.

How to open word file in background using vb.net?

I am working on creating multiple documents from source document.
I am using:
objWordApp.Documents.Open("D:\Template\Aptletter.doc")
I modify the above document and save in another folder.
While creating documents, word files are opening and closing multiple times. So user unable to do another work on the same PC.
How to stop open file or Is there any method to modify document without above method?
So please suggest
Thanks in Advance
DEV
The visibility of a word document being controlled via interop can be set using the WordApplication.Visible attribute.
This attribute is, as you can see, at the Application level. If you've already opened a document using that WordApplication, you can't suddenly make the application invisible using the attribute.
What you can do, though, is create another instance of WordApplication. Call it InvisibleWordApplication for clarity, and set InvisibleWordApplication.Visible = false right from the start. Then open your document using that application, and you should be set.

Using querySaveDocument to additional information

We are trying to save some additional information with a document using the QuerySaveDocument event. However it seems that it is not being triggered at all.
<xp:executeScript script="#{javascript:setField(document1, 'cCustAddr1_fi', 'test');}">
</xp:executeScript>
This is our basic script. All the setField() method does is use replaceItemValue to try and set the field. However it seems that QuerySaveDocument is not even being triggered since we can write pretty much anything and the document will still save without problem, even if it would be impossible to execute.
We have also tried using a simple document1.getDocument().replaceItemValue() script, but again I dont think it even attempts to execute. Our documents save perfectly fine too,
Do you see any reason for this, are we doing our saving wrong, or should we be attaching data onto the document in another way?
Thanks.
Your other question on Unplugged (Using other dialog controls in iOS) suggests that you are using the Unplugged Mobile Controls project.
If that is correct then my comment above applies - the querySaveDocument event won't get fired . You can look at the code in UnpSaveDocument.xsp and possibly add your own SSJS code to that.
Alternatively, if you want an additional item created on your back-end Notes document then you should just be able to add a hidden field to the UnpFormEditor that is bound to the document1 data source and using the relevant item name you want.

How to Select Masters Via Visio VBA

Is it possible to programmatically change the selected master within a specific stencil document in Visio, using VBA? If so, how would I go about doing it?
It doesn't seem possible to use the Window.Select method, since that seems to only work in the drawing page...
With Visio API only it is only possible to get selected master(s) using the Window.SelectedMasters property, but not set it (it is a readonly property).
So, there is no direct solution.
If you are okay with (sort of) workaround, you can take a look at mine here (the same question):
http://visguy.com/vgforum/index.php?topic=3378.msg13172#msg13172
It simply sends keyboard keys to the stencil window right number of times :)

Create a shared copy and paste menu for my grids

I have 20 or so grids in my application suite. I'd like to create a global copy/paste context menu which I can bind to every single grid rather than code in each form.
I am unsure what is the best way to achieve this, I have started to create a class with my menu in it, but get stuck at the point of adding the actual menu options. For example I know I'll need to call a "copy" event, but I also know I'll need to tell it what I am copying, and I cannot see how that is done in vb.net when you can only add the address of a method minus parameters.
e.g.
.MenuItems.Add("Copy Cell", New System.EventHandler(AddressOf CopyCell))
Obviously I want "CopyCell" to only be coded in one place as well, rather than repeated in each form. I will always be copying the same object (SelectedCellCollection).
I am not sure how to make the menu have an event with parameters, or how to make it "know" that I want to always copy the selected items. I'm aware that I'd have to do some coding in the form but just trying to work out the way to minimize it.
I have created my own context menu class (via inheritance) with specific copy and paste functionality / options tailored to the grid I am using. It works fine and only needs one line of code per form/grid to activate.