In Word, Programmatically Open New Document Dialog - vba

I am looking for a way to programatically open the "New Document" dialog in Word 2007. It is the same one you get when you select File->New . You can also open it using the FileNew macro or the "New..." menu command. However, I have been unable to find a way to do this programmatically.
I have tried:
Application.Run MacroName:="FileNew"
and
Dialogs(wdDialogFileNew).Show
and
CommandBars.FindControl(ID:=5746).Execute
but both of these open the old dialog, not the new one that word 2007 uses.

If a 'real' VBA command exists for open that dialog, I can't find it. However, I did find this utterly lame workaround via some quick googling:
SendKeys "%"
SendKeys "F"
SendKeys "N"
It does what you want though! Found it here http://www.eggheadcafe.com/software/aspnet/32228837/new-file-dialog-in-word-2.aspx

You could get the Command ID for the button and execute it?
Dim c As CommandBarControl
Set c = CommandBars.FindControl(ID:=18)
c.Execute
Control ID 18 is the word application ID for the New... button.

I think that you can just use:
Documents.Add
without any parameters.

Related

Disable File>Share in Excel with VBA

I need a way to disable the ability for a user to go to (or use) the menu File > Share
I have similar for other save commands like below but need something for this feature as well
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False
I have tried:
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Share").Enabled = False
to no avail
My aim is to stop users saving copies of this file (Hosted on a server), I fully understand Excel isn't meant to be secure and there is always a way to do this but want to make it as hard as I can for the average Joe
Regards
You could use a for each loop to extract the available commands:
' Iterate available commands from the file command bar.
Sub PrintAllCommandBarControlNames()
Dim cbControl As CommandBarControl
For Each cbControl In Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls
Debug.Print cbControl.Caption
Next
End Sub
Run on Excel 2010, I couldn't find a share option. Might just be my system. The above returned:
&New...
&Open...
&Close
&Save
Save &As...
Single Web Page (*.mht)
Save &Workspace...
File Searc&h...
Per&mission...
Per&mission
Ch&eck Out
Ch&eck In...
Ve&rsion History...
We&b Page Preview
Page Set&up...
Prin&t Area
Print Pre&view
&Print...
Sen&d To
Propert&ies
&Recent File Name Goes Here
&Recent File Name Goes Here
Sign ou&t
E&xit Excel
The 'backstage' menu (that you get when you click top left File menu) is effectively part of the Ribbon, and not a Command Bar. If you tried disabling Save for instance, using your example, you'll find they don't work on 2010/2013 etc.
There is this answer which tells you how to manipulate those menu items in the ribbon: Remove "Save & Send" from File menu in Excel 2010 using custom XML and one of the items is called TabShare.

How to open object(macros) and use the form in it using command button?

Hi GUYS , I will explain my problem:
1- I use object command in excel to bring another excel file see image(1)object_image
2- I want to make command button which links to the object
3-image (2) show the worksheets and forms note when I close the book, the object's book change image all
so what I want is when I click the command button in my first excel it will open the form and allow me to change in the second excel.
this is my code
Private Sub CO1_Click()
Workbooks("Book3").Worksheets("Sheet1").CommandButton1.Value = True
Application.Run Workbooks("Book3").Worksheets("Sheet1").OnAction
trainUserForm.Show
End Sub
please, guys, i need this to finish my work and thx :)

MS Access 2016 report contains a hyperlink pathway. On Click event VBA to open specific hyperlink clicked

I have a report based on a search parameter form.
Is it possible to use a textbox named txtFullScanPathway included on the report as a hyperlink to open that specific pdf in an On Click Event perhaps?.
Alternatively, is there a way to have another form in datasheet based on the parameter form to open the results?
The project purpose is to allow a quick search of PDF Manifests... the user will open a report using a command button on the parameter form (This is all working now) and there may be several to go through.
The Report generated has a file pathway which has been generated by the parameter form, and that field is "FullScanPathway".
The user is trying to find a pdf based on this "manifest" and so there may be several results to look through and I was hoping to provide an "On Click" event to open the pdf that belongs to FullScanPathway...
Are there any good examples on how to accomplish this?
I have tried the Follow Hyperlink method, but do not like the security errors it throws...
Any help or ideas would be sincerely appreciated !
William
Try:
Dim wsShell As Object
Set wsShell = CreateObject("WScript.Shell")
wsShell.Run Chr(34) & Me!FullScanPathway & Chr(34)
Set wsShell = Nothing

Copy from Excel to Browser

How do I "paste" in Selenium/VBA to browser textfield?
I downloaded and installed this: https://code.google.com/p/selenium-vba/
I managed to start Selenium in Firefox (CTRL-ALT-S) and recorded my steps for automation. I changed the code language to VBA in there and copied it to paste it in Excel.
For those of you who want to know what to do in Excel (2013):
Right click "Start"
Customize Ribbon
Check "Developer Tools" on the right
Click OK > Click on "Developer Tools" > Click "Visual Basic" > Click "Extras" > Click "References" > Look for "SeleniumWrapper Type Library" and check it > Click OK > In Menu bar click on the top arrow beside "Paste UserForm" > Click "Module" > Now paste the VBA Code from Selenium (Firefox) Plugin in there
Everything works perfectly fine but I want it to do repetitive web browser tasks so it should copy Excel cells and paste it in Textboxes in Websites for example in the Google Searchbar.
I already found a solution for the copying part:
Range("A1").Copy
It works but I can't find any working solution for the pasting part. Tested but didn't work:
driver.findElementById("ID").SendKeys "^v" gives out "v" instead of pasting.
driver.findElementById("ID").SendKeys(Keys.chord(Keys.CONTROL, "v")); Doesn't accept ";" and also doesn't work without.
I also tried several "Wait" and "Sleep" codes but neither do I know for sure which of them actually work nor if they are necessary.
driver.action.key_down(: control) Didn't work.
driver.findElementById("ID").keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u0076')).perform(); Syntax error, without ";" "Error: List Delimiter" and marks the "." between "String" and "value".
I am grateful for any advice!
The easiest way is to send the text:
Dim driver As New FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
driver.FindElementById("searchInput").SendKeys [A1]
If you really need to use the clipboard:
Dim Keys As New Selenium.Keys
Dim driver As New Selenium.FirefoxDriver
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
driver.SetClipBoard [A1]
driver.FindElementById("searchInput").SendKeys Keys.Control, "v"
Of course it depends on the kind of element you want to paste the text to, but how about just setting the element's value directly;
driver.findElementById("ID").text = Range("A1").value2

Does Excel VBA object model allows for access to keyboard shortcut to VBA IDE menu items?

Does Excel VBA object model allows for access to keyboard shortcuts to VBA IDE menu items ?
(I would like to create additional item in menu and connect it with choosen shortcut)
For example code below returns "C&lear" which means you can access "Clear" item by typing "l" when the "Edit" group in VBE IDE is active, but you can also access "Clear" by typing "Delete" button alone :
Debug.Print Application.VBE.CommandBars(1).Controls(2).Controls(6).Caption
is there a way to find pragrammaticaly direct shortcut to item in IDE menu ("Delete" in the case above) ? I would like to add item to VBA IDE menu with new custom shortcut ?
Debug.Print Application.VBE.CommandBars(1).Controls(3).Controls(6).Caption
returns "&Immediate Window" but you could also access Immediate Window by direct shortcut "Ctrl+G"
is there a way to find pragrammaticaly direct shortcut to item in IDE menu ("Delete" in the case above)
Yes, there is. Try this
Debug.Print Application.VBE.CommandBars(1).Controls(2).Controls(6).ShortcutText
This will give you Del
Followup from comments:
Dim b As CommandBarButton
Set b = Application.VBE.CommandBars(1).Controls(2).Controls(6)
Debug.Print b.TooltipText
returns:
C&lear (Del)
Similarly,
Set b = Application.VBE.CommandBars(1).Controls(2).Controls(6)
Debug.Print b.TooltipText
returns
Export (Ctrl+E)