Edit Excel JumpList via VBA - vba

I'm desperately trying to find how I can access the JumpList via VBA.
I currently have a bit of code that rips apart an Excel file into separate sheets and saves them all separately (about 50+ sheets) This unfortunately triggers the JumpList to be updated with each individual file which gets a bit annoying especially as Excel's own 'recently used files' doesn't get updated.
What I want to do is either a) stop them being added to the Jump List or b) recreate the jump list.
Having looked around the easiest way to do this is to reference the WindowsAPICodePack. Either from it itself or the PresentationFramework Library. However I can't for the life of me find how to access these from Excel. I've seen a lot of references to 'Tools/AddIns/Automation' However I can't see that in my Office 2013. Can anyone help at all as to how I could include these references or access the JumpList

The VBA work-around is to set the Excel's jump list file to read-only, after that whatever you do, the list is not updated. Once you are done and want to resume the list update feature just the set the file attribute as normal.
Sub manageJumpList(bAllowAdd As Boolean)
Dim strJumpFile As String
'/ Excel's Jump Location
strJumpFile = Environ("userprofile") & _
"\AppData\Roaming\Microsoft\Windows\Recent\AutomaticDestinations\b8ab77100df80ab2.automaticDestinations-ms"
If Not bAllowAdd Then
'/Stop from updating
SetAttr strJumpFile, vbReadOnly
'<<After doing this, whatever files you open, they will not be added to recent list>>
Else
'/ Allow to update
SetAttr strJumpFile, vbNormal
End If
End Sub
Sub test()
'/ Stop Updating JumpList
Call manageJumpList(False)
'/ Start Updating JumpList
'Call manageJumpList(True)
End Sub

Related

Is it possible to run a VBA macro in a READ-ONLY protected PowerPoint?

My colleague and I have been on a six month quest for a VBA macro that can run in a Read-Only, password protected PowerPoint.
Is it possible or will PowerPoint always block the VBA macro from running in the presentation, because of the read-only status?
Private Sub CheckBox1_Click()
Dim ppShp As Shape
Dim eff1 As Effect
Dim ani1 As AnimationBehavior
With ActivePresentation.Slides(1)
Set ppShp = .Shapes("Oval 4")
Set eff1 = .TimeLine.MainSequence.AddEffect(Shape:=ppShp, effectId:=msoAnimEffectAppear)
End With
End Sub
I tried using If ReadOnly = True Then conditions.
I want the user to use the macros and save, but not edit beyond that, or to open and 'look under the hood'.
(It's all for an educational program)
We get
Run-time error '-2147467259 (80004005)'
Presentation (unknown member) : Invalid request. Presentation cannot be modified.
Perhaps as a work around you could save a copy of the original read only presentation, run your macro on the new version and then save the new version as read only?
Hello this might be too late but if I understand you correctly, you want that other users can read, execute macros but not able to read the code behind it. Saving should be okay.
The macro that you used should be password protected. First go to the editor, select the macro and view the properties/protection and set up a password
Then after you are done, close the file. Right Click on the file/properties and check readonly. Users will then have access to the macro, not being able to see what code is behind it and can save it.

Excel 2013 to 2010 backward compatibility issue with ActiveX (NOT Dec14th update issue)

I am transitioning a set of interrelated Excel documents that use VBA code for lookups, data manipulation and calculations from Excel 2010 to Excel 365. I have both on my development machine, however these get sent (via email) to customers all over and then returned. I use .xlmb file formats for the file size savings however this doesn't seem to be affecting the outcome.
CURRENT ISSUE
When I save a workbook using 365 on my development machine, users get errors when performing an action that runs my VBA code when run from a machine that only has 2010 installed (if both versions are installed, the behavior does not seem to happen). I have focused the problem to when there is code in a module and there is an ActiveX control on a sheet. ONLY this combination seems to create the issue.
The test file/code I've created that consistently shows the issue is a workbook with the following code in a module:
Dim strBook As String
' Worksheet Names
Public Const wksTest = "Sheet1"
Public Function TestMe(PassedSheet As String)
strBook = ActiveWorkbook.Name
Workbooks(strBook).Worksheets(PassedSheet).Protect
Workbooks(strBook).Worksheets(PassedSheet).Unprotect
MsgBox "Worked from function", vbOKOnly, "Response"
End Function
And code in the sheet. It works with this code and selecting cell B2 protects and then unprotects the sheet while displaying message boxes:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row = 2 And Target.Column = 2 Then
strBook = ActiveWorkbook.Name
Me.Protect
Me.Unprotect
MsgBox "Worked from sheet", vbOKOnly, "Response"
Call TestMe(wksTest)
End If
End Sub
However if an ActiveX Command Button named "TestButton" is added to Sheet1 and this code is added:
Private Sub TestButton_Click()
strBook = ActiveWorkbook.Name
Me.Protect
Me.Unprotect
MsgBox "Worked from Button", vbOKOnly, "Response"
Call TestMe(wksTest)
End Sub
The workbook will no longer function if saved from 365 and opened with 2010 on a machine with only 2010 installed.
This is unique enough that it has been difficult to test. Currently, the only option I seem to have is replace all my command buttons with Form Controls. This also is a separate issue from the security update (which is really muddying the waters).
I would love to get feedback on possible fixes for this issue or even just confirmation from others that this is an Excel issue and not somehow limited to our installation.
Thanks
I was looking for help on a similar question and stumbled on this info on the Microsoft help site. If this doesn't solve the problem you have, it might be a step in the right direction:
"If a workbook contains ActiveX controls that are considered to be Unsafe for Initialization (UFI), they are lost when you save the workbook to an earlier Excel file format. You may want to mark those controls as Safe for Initialization (SFI).
What to do: If you open a workbook that contains uninitialized ActiveX controls, and the workbook is set to high security, you must first use the Message Bar to enable them before they can be initialized."

A private subroutine in VBA is being activated by other workbooks -- Why?

I have a private subroutine in Workbook A that is running any time I open or close and save other unrelated workbooks. I'm trying to understand why that occurs so I can capture all potential errors that may occur.
The subroutine is an ActiveX ComboBox named TabProg that is supposed to run when the value is changed. I have currently added in a check to see if the active sheet trying to run the code is the "Program Loading" sheet to try and divert any potential errors. See snippet below.
Private Sub TabProg_Change()
MsgBox "Whomp!", vbOKOnly + vbExclamation
If ActiveSheet.Name <> "Program Loading" Then 'do nothing
Else
'Run desired actions on "Program Loading" sheet
End If
End Sub
Any known reasons why this is occurring or other ways to catch it would be helpful. Thanks!
Edit 1: I do not see this problem occur when I open other workbooks in new instances of Excel.
Edit 2: I have modified the code to include a message box whenever the code tries to run, now shown above. It is occurring every time I open or close and save any Excel file, including the file itself. The drop down list in the ActiveX ComboBox is a list of names that correspond to 10 sheets within Workbook A. If I delete the sheet that ComboBox is currently set to, the error will disappear. If I change the ComboBox to a different sheet, the error will reappear.
From what you've wrote in your question, I don't think that your problem can be replicated. I think that your Excel file got corrupted. I had an experience like this: had a file for experimenting with macros, one of the macros used Excel Speech object to say "This is a test file" on opening that particular file. The macro was (as all other macros from this file) not part of my PERSONAL workbook, it was assigned to ThisWorkbook in the bespoke file. At some point a funny thing happened: this "This is a test file" private subroutine got activated every time I opened any Excel file. I did not find any solutions, I just deleted the file where the subroutine was stored. This resolved the problem, but I have no explanation for this. I am afraid the same thing may apply to your file, but maybe other folks have a better idea... maybe it's something in the system registry??? I don't know. Can you manually copy elements / code from this file to a newly created file and just delete the original?

VBA Dialogs.Show doesn't display warning message

Have Excel (2010 in my case but I think it will be the same also in other versions) with two workbooks. Save first one with name "1.xlx" (example) via Save As dialog. Save second one with the same name "1.xlx" to different location. Excel will not allow it with following warning message:
"You cannot save this workbook with the same name as another open workbook or add-in. Choose a different name, or close the other workbook or add-in before saving."
So far so good. But my problem is that I need to invoke dialog via VBA. I am using following code:
Sub test()
Application.Dialogs(XlBuiltInDialog.xlDialogSaveAs).Show
End Sub
Now I am trying to save second workbook (with the same name to different location) but when I click to 'Save' button nothing happen, no warning message. If I wouldn't know what is wrong it would be very difficult to tell. I didn't change any setting (there is nothing as DisplayAlerts set to true or so). Any idea how make SaveAs dialog invoked via VBA to display similar warnings?
I'm not sure why that doesn't give you an error, but it doesn't me either. If you use Application.FileDialog, you can get that error.
Sub testts()
With Application.FileDialog(msoFileDialogSaveAs)
.Show
.Execute
End With
End Sub
Or you could use GetSaveAsFileName and check the names of all the open workbooks and generate the error yourself.
Can you try with the below code on starting on your code.
Application.DisplayAlerts = True

excel vba projects not closing

I'm going through 100s of excel files in VBA, extracting certain data and copying it to a main spreadsheet in a main workbook. I have a VBA script that resides in this main spreadsheet.
I'm trying to get each source workbook to close after I open it and get what I need. It looks something like this:
dim main_wb
dim source_wb
set main_wb = activeworkbook
Loop thru workbook names
set source_wb = workbooks.open(a_workbook_name)
do some stuff
eventually copy a few rows from various sheets into the main wb
source_wb.close()
set source_wb = Nothing
End Loop
The problem is that it SEEMS like the system is continuing to keep the file open in the project explorer ... and eventually it runs out of memory or something. All files work fine individually. It's only when I attempt to process them all at once that I have a problem. The workbook "closes()" but the project still exists in the project explorer in the developer window.
How do I tell it to close out a project. I need to be able to, no BS, close the project and go on to the next one for hundreds and potentially thousands of files - automatically, in code, no intervention from user.
try... It works for me in a similar type of program.
'closes data workbook
source_wb.Close False
I recently had this problem: I have a workbook that grabs data from other workbooks that I use as databases. On one of these, I inadvertently placed some code. This caused the workbook to remain visible in VBE even after it had been closed. My solution was to keep my database workbooks free of code, and that solved the problem.
It seems that the VBE editor is not always visible to the workbook that is being closed.
I included the following code in my ThisWorkbook module which comes from a comment in another thread and this resolved matters.
http://dailydoseofexcel.com/archives/2004/12/11/google-desktop/
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
' -------------------------------------------------------------
' this code ensures that the VBA project is completely removed
' when the workbook is closed
' http://dailydoseofexcel.com/archives/2004/12/11/google-desktop/
' -------------------------------------------------------------
If Not (Application.VBE.MainWindow.Visible) Then
Application.VBE.MainWindow.Visible = True
Application.VBE.MainWindow.Visible = False
End If
End Sub
Solution :
Manage your Save (Yes, No, Cancel)
Destroy links to Addins in your Application
Close these Addins
Close your Application