Saturday, June 10, 2017

Be careful! Parts of your document may include personal information that can't be removed by the Document Inspector

Goto File in the upper left hand corner, then Options > Trust Center > Trust Center Settings > Privacy Options > then un-check the check box that says "Remove personal information from file properties on save", then hit OK.

Sunday, June 4, 2017

AppActivate

https://msdn.microsoft.com/en-us/library/office/gg278643.aspx

Best Practices

Avoid use Excel's built-ins: ActiveWorkbook, ActiveSheet, and Selection: capture return values, and, favor qualified expressions instead.
Use the built-ins only once and only in outermost macros(subs) and capture at macro start, e.g.
Set wkb = ActiveWorkbook
Set wks = ActiveSheet
Set sel = Selection
During and within macros do not rely on these built-in names, instead capture return values, e.g.
Set wkb = Workbooks.Add 'instead of Workbooks.Add without return value capture
wkb.Activate 'instead of Activeworkbook.Activate
Also, try to use qualified expressions, e.g.
wkb.Sheets("Sheet3").Name = "foo" ' instead of Sheets("Sheet3").Name = "foo"
or
Set newWks = wkb.Sheets.Add
newWks.Name = "bar" 'instead of ActiveSheet.Name = "bar"
Use qualified expressions, e.g.
newWks.Name = "bar" 'instead of `xyz.Select` followed by Selection.Name = "bar" 
These methods will work better in general, give less confusing results, will be more robust when refactoring (e.g. moving lines of code around within and between methods) and, will work better across versions of Excel. Selection, for example, changes differently during macro execution from one version of Excel to another.
Also please note that you'll likely find that you don't need to .Activate nearly as much when using more qualified expressions. (This can mean the for the user the screen will flicker less.) Thus the whole line Windows(expression).Activate could simply be eliminated instead of even being replaced by wkb.Activate.
(Also note: Many .Select statements do not contribute anything and can be omitted.)
(I think that Excel's macro recorder is responsible for promoting this more fragile style of programming using ActiveSheet, ActiveWorkbook, Selection, and Select so much; this style leaves a lot of room for improvement.)

toggle between apps with powershell

Use single quotes in your SendWait calls. I.e.: SendWait('%{TAB}%{TAB}') 

So I think I figured it out. You don't want to do an ALT + TAB for the toggle since this is a Z-Based swap. This means it only toggles between the first and second applications running. However, if you do Alt+Shift+ESC, this will tell the system to pull the last item in the list and bring it forward
I figured it out.
Use SendWait("%{TAB}")
In powershell the only way to use the alt key seems to be with the % symbol.

Saturday, June 3, 2017

Cycle through open Windows applications

VBScript in WHS was the way to go.



'****************************************************************************************
' Script Name: ApplicationCycler.vbs
'      Author: Ian Burns
'        Date: 2 Dec 2011
'   Edited By: Makaveli84
'   Edit Date: 30 Aug 2014
' Description: VBScript for Windows Scripting Host. Cycles through any applications 
'              visible in the Task Bar giving them focus for a set period.
'       Usage: Save file to Desktop and double click to run. If it isn't already running,
'              it will start. If it is already running, it will stop.
'*****************************************************************************************
Option Explicit

Dim wshShell
Dim wshSystemEnv
Dim intCycle
Dim intSleep
Dim intTimer

' Cycle every 5 seconds / Check on/off status every 250 milliseconds
intCycle = 5000: intSleep = 250: intTimer = intCycle

Set wshShell = CreateObject("WScript.Shell")
' Volatile environment variables are not saved when user logs off
Set wshSystemEnv = wshShell.Environment("VOLATILE")

' Check to see if the script is already running
If len(wshSystemEnv("AlreadyRunning")) = 0 Then

    ' It isn't, so we set an environment variable as a flag to say the script IS running
    wshSystemEnv("AlreadyRunning") = "True"

    ' Now we go into a loop, cycling through all the apps on the task bar
    Do While len(wshSystemEnv("AlreadyRunning")) > 0
        ' Simulate the Alt+Esc keypress
        If intTimer >= intCycle Then
            wshShell.SendKeys "%+{Esc}"
            intTimer = 0
        End If
        intTimer = intTimer + intSleep
        Wscript.Sleep intSleep
    Loop

Else
    ' Delete the environment variable
    wshSystemEnv.Remove("AlreadyRunning")
End If


' Tidy up
Set wshSystemEnv = Nothing
Set wshShell = Nothing

Windows API

http://www.techrepublic.com/blog/10-things/10-plus-of-my-favorite-windows-api-functions-to-use-in-office-applications/

https://msdn.microsoft.com/en-us/library/office/aa165081(v=office.10).aspx


https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/com-interop/walkthrough-calling-windows-apis

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/com-interop/walkthrough-calling-windows-apis

http://allapi.mentalis.org/vbtutor/api1.shtml


http://vbadud.blogspot.ca/2007/06/show-all-processes-using-vba.html

VBA Tutorial - good beginners primer

http://ritc.rotman.utoronto.ca/documents/2017/RIT%20-%20User%20Guide%20-%20VBA%20API%20Documentation.pdf