Disable File>Share in Excel with VBA - 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.

Related

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 :)

selectDialog with address bar instead of dropdown with Photoshop script

I'm writing a custom script for Photoshop to handle batch processing of images. I have two input folders and an output folder that I need to specify. Right now I'm using something like this to select my folders:
var inputFolder = Folder.selectDialog("Select a folder of images to process");
Because I'm working on a server with a pretty deep folder hierarchy, it can be a real pain to select through the drop-down menu that Photoshop presents to me in this dialog.
It would be so much easier to have a folder selection dialog with an address bar and quick access panel like this:
All other PS scripts that I've been digging around in use the Folder.selectDialog method to set file paths to a variable. Is there a reason for this? If not, then how can I instruct Photoshop the second style of folder navigation dialog?
It doesn't appear that Adobe supports this dialog as a folder selecting option.
There was a similar thread to this posted on the Adobe forums where a workaround was suggested:
https://forums.adobe.com/thread/1094128
The solution that was suggested is to use a saveDialog function instead of selectFolder. This gives you the folder dialog that we want, but comes with the downside of having to type a dummy name into the filename path. It also says "Save As" on the top of the dialog box, which is confusing.
Here's what was offered:
by lilsmokie on Nov 8, 2012 2:19 PM
var dskTop = Folder.desktop;
var dskPth = String(dskTop);
var newSpot = new File(dskPth+"/poop");
var selectedFolder = newSpot.saveDlg('Select Destination Folder');
var illFilePath = selectedFolder.path;
alert(illFilePath);
This opens the dialog at the desktop. Then put "poop" or whatever you
like in the text field. There the user can navigate to where ever.
When they it save illFilePath will have the folder path. Not perfect
but its close enough for me right now.
I've also discovered that I can set the starting location of the selectDialog by using selectDlg instead:
var outputFolder = Folder(app.activeDocument.path).selectDlg("Select a folder to output images to:");
This gives some control over the starting location so that the user doesn't have to click through a million dropdowns.
At the bottom of your first screenshot you can see the unput text area Folder: This PC. It works just like an address bar. You can type (or paste) something like \\server\work\folder\subfolder into this area and you get this folder ('subfolder' in this case) immediately.
On MacOS this dialog doesn't show the Folder: ... input area. But you can press Cmd-Shift-G and get the native system 'address bar' anytime.

Import or Add code to an add-in dynamically

I am working on a project where I have created a PowerPoint addin. The concept is this will only contain an user form, with a list box. Based on the user selection other modules (bas files) will be added or imported to the presentation and the code will be executed.
I don't want to include all the modules in the add in as depending upon the requirement I can do the modification and then can store in a shared folder. So every time user uses the addin they can have the updated version. So I don't have to re circulate the addin with every change.
I have a blank module where i import the code from a text file (code from bas file saved as text) and it runs.
I can import the bas files, also using inserFrom file option I can import code from a text file, but problem is it's always getting added to the current presentation code window. But I want to add the code to the addin code pane.
I have a blank module in the addin called "tempCode", where I want to update the imported code, but I am not able to do so.
It works fine when I am editing the addin as a ppt, but when I convert ppt to an addin the concept is not working.
Any ideas how I can add the code to the addin code pane rather adding to the active ppt.
Code details:
I have a user form, with a list box.
It has 3 items.
Option 1
Option 2
Option 3
If user selects any option, let's say option 2, the code for option 2 will be imported from a text file to the working module.
And a command button to run the selected.
Name of working module is “Mod_Working”
Name of text file is “C:\Code\Option2.txt”
Below is the code I am using:
Sub ImportSelected()
With ActivePresentation.VBProject.VBComponents(“Mod_Working”).CodeModule
.DeleteLines 1, .CountOfLines 'it deletes any existing code
.AddFromFile “C:\Code\Option2.txt”
End With
End Sub
Code in text file:
Sub Test
Msgbox “You selected Opt 2”
End sub
Code of Command Button:
Private Sub Cmd_run_Click()
Application.Run “Mod_Working.Test”
End Sub
This works in ppt mode but not when converted to addin.
Why not do this:
- In the shared folder, mark the add-in file as read-only (right-click, properties). This prevents the file being in-use when people are using the add-in (at least it works that way in Excel)
- When you have an update, simply replace the add-in and set it to read-only again.
Alternatively, check out: www.jkp-ads.com/articles/updateanaddin.asp

Access command from the Quick Access Toolbar

When I use a macro, that opens a new email from a template, I would also like to access one of the commands from the Quick Access Toolbar and make sure a particular option is selected from the drop-down list on this command.
For example, the tab on the toolbar is called 'Add-Ins' and within this tab the area on the toolbar is called 'custom toolbars'. There is a command in this section entitled 'ACT! History', and I would like to automatically chose 'None' from the drop-down list for this command. I do have a screen grab of the toolbar I can send you if this helps.
The current macro is a very simple one as the text below shows.
Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate("C:\Users\jfield\AppData\[file location]\New Placement!.oft")
newItem.Display
Set newItem = Nothing
End Sub

In Word, Programmatically Open New Document Dialog

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.