Stop the mahem! The VBA Windows collection changes each time you activate a new windows. How to get some sense back!

Ok – so this guy give me the one tip that mattered. Application.Windows(1) is the active window. ALSO – you can change the caption of the window. IF you have a workbook and need to show  2 or more worksheets in as many windows – then it renames the sheets and adds :1 and :2 – which DO NOT CHANGE. But the windows(1) is NOT reliably window(1) the next time you interact with the windows.

So if you want sheet1’s window to return sheet1 and sheet2’s window to interact with sheet2 – then here is some code to help one understand what is going on. What I am going to do is change the :1 to :DELTA and :2 to :SOURCE and ensure that those windows show the delta and source worksheets respectively

[vb]

Sub Test_WindowIndexes()
‘ Here is the guy to inspired me to fiddle and get some understanding. It is mental but
‘ there is some hope is his bottom line. https://www.engram9.info/excel-vba-programming-3/the-workbook-and-window-objects.html

‘ before you run this – make a workbook with 2 worksheets
‘ rename them something memorable

‘ Next – simply make a new window . Use hte View Ribbon->New Window button
‘ or Set mywb = workbook.newWindow command here in VBA (in future)

Debug.Print "*********************new" ‘ just a line so you can see what
‘is going on between running this and loooking in the immediate window

Debug.Print "activesheet: " & ActiveSheet.Parent.Windows(1).Caption
ActiveSheet.Parent.Windows(1).Caption = VBA.Replace(ActiveSheet.Parent.Windows(1).Caption, ":1", ":DELTA")
Dim vvar As Variant
Dim w As Window

‘ lets set aside some static instances of the windows as they are right now
Dim winds As New Collection
winds.Add ActiveSheet.Parent.Windows(1) ‘ the active screen
winds.Add ActiveSheet.Parent.Windows(2) ‘ some random worksheet

‘ lets cycle through the worksheets.
‘ Set a breakpoint AFTER the Next – play with the windows and re-run this loop.
‘ the Application.windows collection CHANGES INDEXES – how unstable!
For Each vvar In ActiveSheet.Parent.Windows
Set w = vvar
Debug.Print "collection: " & w.Caption & " –> " & w.ActiveSheet.Name
Next

‘ now let VBA muck with the active window
winds(1).activate
Debug.Print ".windows(1):" & Application.Windows(1).Caption
Debug.Print "w1:" & winds(1).Caption
Debug.Print "w2:" & winds(2).Caption

Debug.Print " … now switch to winds(2) as active"
winds(2).activate
Debug.Print ".windows(1):" & Application.Windows(1).Caption
Debug.Print "w1:" & winds(1).Caption
Debug.Print "w2:" & winds(2).Caption

‘ wind(1) and winds(2) are finally static and no longer dependant on windows(1)
‘ got a solution now. How mental is this!? Perhaps this was out the Excel Team’s area
‘ of control. The Excel team would not have let this mahem propagte.

End Sub

[/vb]

Precedents limitations in Excel Formulas – VBA

I am trying to find the fastest way to store and retrieve a reference to a cell in another workbook. The sheet I am making is a delta record of what a spreadsheet that archives where data USED to be and make a quick link to get back to that data. So – I thought I used a simple formula =’somesheet somewhere’!$A$2 then I could intelligently pick up its information using a formula. Well – in short you CAN – if it is not off sheet. All mine are a off sheet – so the trick is to show to “Trace Precedents” arrows and use the Range.NavigateArrow() method to look back. THAT WILL WORK – but I think I will just store the long string and use Range(“‘somesheet somewhere’!$A$2” ) and be done with it. I think it will be less compute intensive. The guy in this article did all that cool stuff I am NOT going to use – very ingenious. Thanks Excel for exposing all sorts of goodies for us to use.

Hard Drives and speed of writing – what we need to know to maximize

First start by reading this very well written article that explains all one needs to know in simple terms. SSDs, Sata I, II, III hard drives, flash drives, thumb drives and SD cards are all discussed. In short lets follow the data flow. The SLOWEST part is what YOU need to address – lets discuss all the parts

a) bus speed – so USB 2, eSATA, 3.0, thunderbolt, 3.1, thunderbolt 2 and thunderbolt 3 are IN ORDER the slowest to fastest. (usb 3 vs thunderbolt 2) This is talking about the computer that one plugs things into. (I might have the order slightly off – so comment if I do) … Continue reading

Dealing with Double Precision Applanix data times – all the links to make it work

I was asked to look into why 1 of 3 parts of data was 6 days earlier than the other 2 parts. Well it turned out to NOT be IGES data – but it was raw binary data dumps from a LiDAR system. The data was Applanix proprietary data format that is likely written the way it is to allow high speed data writing. First, all the data is bound by $GRPXX and $# where XX is a hex group code. To undo all the data and make some sense of the time stamps it took an awful lot of digging. Here are the links and learning I found. Continue reading

AutoHotKey example of clicking that popup FOR YOU

A user asked me a question to get past a recurring popups . It seems like this is a 1 time job – so cheezy solutions are acceptable (right!?)

Write a quick script to click the annoying popup for you. I did for another example and the code is below on how I did it. My example checks for 2 things a) do I see the popup and b) is Excel running – but the concept applies (and it works.) Download AutoHotKey – corps block this – so … do it at home and bring it in … then make the script and generate a .exe and run it in the background while you are doing your task.

Here is my script that worked for me … Continue reading

Using Visual Studio to Create a C# installer

C# Installer Intro:

This is a more complete list of all of the different processes you might want to have in an installer for c# in visual studio 2017. I have collected this data from across several different people on the internet but there seems to be no complete list anywhere so here you go. First thing is that if you want a free installer, what you have to do is to look for something called setup project. Here is a link to the download. https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects

Step By Step Guide

initial setup

#1: Make sure that the download is installed. Simply double click on the download

#2: Open Visual Studio and open the solution that you want to add an installer to. Then right click on the solution itself within your solution explorer, then Add, then New Project. A frame will pop up called Add New Project. From here I recommend Setup Project. Though you could use the Wizard, you will learn more just doing each part on your own. Make sure you name it before pressing OK. It is now a good idea to open the properties of the setup project and change the author and manufacturer. This affects the folder names that it will be stored in.

Get your files to load

#3: Now you should have a screen that says File System come up. If not, don’t worry all you have to do is right click on your newly created setup project, go to view and then File System. From here you can access the different things you might want to modify when your installer runs. Application Folder represents the actual folder that will be created and filled with your source files. the other two are fairly self explanatory as the users desktop and programs menu.

#4: Now you need to choose what files you want to add to your installer. Right click on application folder and Add. From here you have three options. Folder, project output, file, or assembly.  Project output is a good option because it auto-detects what is in your C# code and finds a way to insert what is need into your installer. If, however, you have additional files that you wish to add, you can choose either folder, or files. These will come in handy later.

#5: As for the Desktop and programs menu. If you want you can add a shortcut to either of these. If your program is an exe file and it needs to be run then this is a good option.

Setting up the files that you have

#6: It is wise to set up any dlls or other assemblies to be in the proper format. In my particular case I was using COM dlls and so i had to make sure that they were registered correctly. In order to do this I set the Register to vsdrfCOM. I was unable to figure out exactly how to get registry to work for these direct from the installer. As a result I was forced to build a program to do it for me and add it as part of the installation.  Update to come If I do figure it out.

Adding an executable to the installation process

#7: You may, as I did, wish to add an executable to your installation process. It is not to hard to do so. First, right click on your setup project in the solution explorer. Go to view, then custom actions. From here you can choose an executable to be an element of your install.

For each of the four folders you are going to right click and then choose add custom action. Here is where the file or folder options from step #4 will come in handy. You can only select an executable from the files you are installing which should make sense because you cant be sure that file will be located in your destination. Select the file you wish to use from the application folder.  Next, open the properties for the newly created custom action. Change the  Installer class field to false. Once this is done your executable will perform the desired program on install.

In order to make sure that the the installer will overwrite older versions of the installed program. and so follow these steps to make sure that it installs properly.

  1. Set Remove Previous Installation as True
  2. Set Detect new version as True
  3. Your C# program’s version must increase with every deployment
  4. You should change version of your installer to one higher version and it will ask you to change product code, select YES.
  5. Do not change your upgrade code, let it be same.

https://stackoverflow.com/questions/3024753/installing-a-new-version-of-a-deployment-project-over-old-version

Conclusion

At this point your installer should build your C# program on a new windows platform.