Thursday, October 17, 2019

Quickly Delete Many Excel Worksheets

In "Reverse the Order of Worksheets in an Excel Workbook" I show a VBA module that I wrote in order to reverse the order of several dozen worksheets in an Excel file.

Each tab contains a summary of data for a week.  After a few years, I had amassed over 100 worksheets.  So I decided I would split the workbook; each one would contain only one year's worth of data.  The workbook for 2018 would have only the 2018 worksheets; 2017 workbook, the 2017 worksheets; etc.

I copied the massive workbook to a 2018 workbook, from which I'd delete all but the 2018 worksheets.  Ditto for 2017, 2016, and, oh yes, 2019, as well.

Unfortunately I found this to be exceedingly tedious.  There didn't seem to be a way to delete multiple worksheets quickly and without many keystrokes and/or mouse clicks.  At best, I was able to select the six tabs that could be displayed at one time by clicking the left-most tab and shift-clicking the right-most tab.  Then I could right-click and delete the selected tabs.  But I'd have to do that about 20 times for each workbook!

So instead, I wrote the following VBA module to do it effortlessly.  Note that each worksheet is named with the date in YYYY-MM-DD format.  (So the worksheet for today would be named 2019-10-17. ) This module was used to delete all the 2019 worksheets.  Rather than write a nested loop to cycle through multiple years, I decided to change the year in the code manually.

  Sub DeleteNewWorksheets()
      ' 2019-03-24 TG  Created to clean up status records
      Dim Sheet As Worksheet
      Dim Book As Workbook
      Dim n As String
      Dim alerts As Boolean
      Dim i As Integer

      alerts = Application.DisplayAlerts
      Application.DisplayAlerts = False
      Set Book = ActiveWorkbook

      i = 0
      For Each Sheet In Book.Sheets
          n = Left(Sheet.Name, 4)
          If n = "2019" Then
              Debug.Print "Deleted " & Sheet.Name
              Sheet.Delete
              i = i + 1
          End If
      Next

      Application.DisplayAlerts = alerts
      MsgBox "Deleted " & i & " sheets.", vbInformation, "DeleteOldWorksheets Notification"
  End Sub


Saturday, June 15, 2019

Plunging Into Celsius

“What is that in Celsius?” asked my European coworker on the other end of an international conference call.  We had started the call by saying how cold it was in the Northeast, -21°F exactly, so I was already asking Google to convert it for me.

“About -30°C,” I replied, not missing a beat.

That’s when I asked myself, “Why do I still use the Fahrenheit temperature scale?”  I decided to switch the units on my favorite weather app and take the plunge to Celsius.

“Isn’t switching to Celsius hard for an old person like you?” you might ask.  Well, I know that water freezes at about 0°C and boils at about 100°C.  Also, I was already accustomed to using Celsius at work, so I knew that room temperature is about 25°C, at least for a warm room.  (I allow my house to stay much cooler in Winter.)

Given these three F-C equivalents, it’s easy to deduce temperatures that lie between 32°F (0°C) and 77°F (25°C) by using ratios.  For example, 12°C, a temperature that is halfway between 0°C and 25°C, is also halfway between 32°F and 77°F, and that’s 55°F.  Likewise, the “quarter points” are 6°C (44°F) and 18°C (66°F), a typical room temperature in Winter.

Below 0°C, I rely on the fact that for every one degree change in Celsius, there is a 1.8° change in Fahrenheit.  As well, for every 2°C change, we experience a 3.6°F change.  So -4°C would be about 7°F below 32°F, or 25°F.

On the upper end of the weather temperature scale, you might get a 35°C forecast, which is 10°C higher than room temperature, or 18°F above 77°F, or 95°F, which (unfortunately) my European coworkers experienced recently.

Have you guessed that I dislike warm weather?

I’m not sure I’ll bother using Celsius in cooking or baking.  First, if I change the units on the oven, my wife will be very upset.  But then I’d also have to convert all the recipes we’ve accumulated.  I don’t see any point in that.

So will you also switch the units in your weather app from Fahrenheit to Celsius?

Saturday, June 08, 2019

Pandora Music Streaming Tweak -- Change the Station Image

I've been a Pandora subscriber since 2006, and I have a couple of well-tweaked stations.  But one of my favorite stations was stuck with the ugly album art of the song that was used as the station seed.  I couldn't find a way to replace the image, and Pandora help had nothing to offer.  So here's how I changed the image:

  1. Log in to Pandora.
  2. Select the station from your collection.
  3. Click the icon to edit the station. (At this time, it looks like a pencil.)
  4. From here you can change the station Name, Description, and Thumb History, but most importantly, the "Seed" that the station evolved from, which is in the section called "Station Created From."
  5. (If there are multiple "seeds" in this section you can skip this step.)  Click "+ Add Variety" to add a new "seed" and choose a favorite song whose album cover you prefer.
  6. Delete the top-most "seed" to set the album cover from the next "seed" as the station image.
  7. You can continue this process until the "seed" that has your favorite album art occupies the top spot.
  8. At this point, you can add back the deleted "seeds" as described in step 5.  But for a mature station, you probably don't need to do this, especially if you've been diligent with the thumbs up button.

Thursday, August 09, 2018

Show Column in Outlook With Email Purge Date

If you're running Outlook in an Exchange environment, and the administrator has defined a Retention Policy, you can use the following kludge to configure Outlook to display a column of dates that the emails will be deleted on.  It's a kludge because the configuration doesn't actually retrieve the Retention Policy from Exchange -- it's up to you to find out what it is and then add it to the configuration.

Select your Inbox and then right click on the message list header and select Field Chooser.


Click the down arrow next to Frequently-used fields and scroll down to User-defined fields in folder.

Click New... and then enter PurgeOn in the Name box, and scroll down the Type box and select Formula.

Enter in the Formula box the DateAdd function that will return a date that's X number of days or months after the message Received date.  For example, if the Retention Policy is 18 months, enter this into the box: DateAdd("m",18,[Received]).  (The first parameter "m" specifies "Month" as the interval.  The number in the second parameter defines the number of intervals, or months in this case.  The third parameter represents the each message's received date.) Then click OK.



Drag the new PurgeOn field that you just created to the header in the position that you'd like the column to appear.


Close Field Chooser and resize the columns so that the dates in the new PurgeOn field display properly.


Note that the dates in the PURGEON column are 18 months later than the dates in the received column.

Unfortunately it seems that each folder (Inbox, Sent Items, etc.) requires its own User Defined Field. The [Received] field is appropriate for use in the Inbox. You might use DateAdd("m",18,[Sent]) in the Sent Items folder.

Again, this is a kludge. If an administrator changes the Retention Policy on the Exchange Server, your new field will ignore the change and blithely continue to show dates based on the old policy.  It may be possible to write a VBA procedure that would run on startup, retrieve the Retention Policy from Exchange and define the PurgeOn field programmatically.  Let me know if you get that working!


A subset of this solution appeared on Microsoft TechNet on 2018-08-09.

Friday, April 13, 2018

Too Much Soap – Too Much Trouble

The effect of using too much laundry detergent makes for a funny, suds-filled scene in the movies.  But the real problem occurs the next time someone does laundry.  All those suds fill the drain line causing turbulence during the rinse cycle, which leads to an overflowing filler tube and a flooded laundry room.

I’d been trying to get my wife to measure the detergent with the cap according to the label.  But she always felt the need to do it her way.  And her way has been to pour the detergent directly into the washer tub, as if adding creamer into coffee.  We’d usually get some overflow in the drain line, and suds would emerge in the adjacent shower.

It’s for this reason I would always buy the cheapest (most watered-down) detergent.  Unfortunately, one day she decided to buy some ultra-concentrated product.  The flood from repeated washings was significant.

I cleaned it up and then set up an electric heater to dry out what I couldn’t remove.  In order to plug in the heater, I unplugged the washer.  So my wife was prevented from running the washer for a few weeks.  That gave me time to snake the drain line (just in case) and run several wash loads with the correct amount of soap.  After a couple of loads, the machine drained better than it ever had before.  I left it this way for a couple of weeks.  In fact, she got mad about that – she wanted to do laundry herself.  Imagine, someone offers to do the laundry for you and you get mad because you can’t do it yourself!

Eventually she settled down enough that she was willing to show her the proper way to:
1. Read the label.
2. Pour the correct amount into the measuring cup.
3. Pour the measured amount from the cup into the tub.
4. Not rinse the cap under the running water.
5. Load the tub right away with clothes.

The last two points are also important.  If you place the cap under the gushing water, suds will form.  Also, if you don’t put the clothes in right away suds will form.  I actually add the detergent after loading all the clothes, making sure to pour it into the water farthest from the water source.

It was amazing that my wife watched and listened to me patiently while I demonstrated the correct way to do laundry.  I didn’t think it was possible.  But it happened, and it felt like my birthday, Christmas and Father’s Day all lumped into one!  Even more amazing is that she’s been doing a lot of laundry over the past couple of weeks, and we’ve had no overflowing water or subs in the shower.  Still, I’m keeping the ultra-concentrated detergent out of sight indefinitely.

Saturday, November 18, 2017

How to Use Excel Pivot Tables to Summarize Continuous Data

Suppose you have a set of data points that represent some quantity in a volume.  It could be temperature in a solid, for example.  How can you use a Pivot Table find the average temperature in a region on the solid’s surface?

Well, if you’re lucky, the region is rectangular, bounded by some Xmin and Xmax and Ymin and Ymax.  Then you can use the built-in Label Filters.

I created a set of data for this article with -20<=X<=20, -20<=Y<=20, -20<=Z<=20.  The temperature is a function of X,Y,Z using the (arbitrary) formula =2.5*X+0.25*Y^2+2.5*SIN(Z).

First, set up the Pivot Table and chose the option to Allow multiple filters per field.


In the screenshots below, we define a Region with Label Filters in the PivotTable Rows within X=[-2,8] and Y=[5,7].  The function is not dependent on the Z coordinate – we’ll use a Page Filter to constrain Z to 0.  As can be seen in the status line of the fourth screenshot below, the average temperature in that region is 16.67 degrees C.






But suppose the region is more complicated than a rectangle, or you want to summarize multiple regions?

You can define a function in VBA to “discretize” the data, as shown in the code sample, below.
Option Explicit

Function Region(rngX As Range, rngY As Range, rngZ As Range) As String
Const regA_Xmin = -2#: Const regA_Xmax = 8#
Const regA_Ymin = 5#: Const regA_Ymax = 7#
Const regB_Xmin = -6#: Const regB_Xmax = -3#
Const regB_Ymin = 5#: Const regB_Ymax = 7#
Const regC_Xmin = -2#: Const regC_Xmax = 8#
Const regC_Ymin = -5#: Const regC_Ymax = -3#
Const regD_Xmin = 9#: Const regD_Xmax = 12#
Const regD_Ymin = 5#: Const regD_Ymax = 7#
Const regE_Xmin = 16#: Const regE_Xmax = 18#
Const regE_Ymin = -15#: Const regE_Ymax = -7#
Dim x As Double, y As Double, z As Double

x = rngX.Value: y = rngY.Value: z = rngZ.Value

If x >= regA_Xmin And x <= regA_Xmax And _
   y >= regA_Ymin And y <= regA_Ymax Then
        Region = "Region A"
ElseIf x >= regB_Xmin And x <= regB_Xmax And _
       y >= regB_Ymin And y <= regB_Ymax Then
        Region = "Region B"
ElseIf x >= regC_Xmin And x <= regC_Xmax And _
       y >= regC_Ymin And y <= regC_Ymax Then
        Region = "Region C"
ElseIf x >= regD_Xmin And x <= regD_Xmax And _
       y >= regD_Ymin And y <= regD_Ymax Then
        Region = "Region D"
Else
    Region = "NA"
End If

End Function

The function accepts three Range type parameters, each of which are intended to be the address of a single cell.  It returns one of five strings: Region A, Region B, Region C, Region D, NA.

The first four constants that are defined in the first two lines are minimum and maximum X and Y coordinates for the region that were defined in the previous example with Label Filters.  So the string “Region A” is returned if X and Y are within those X-Y intervals.

When we type in cell E2 =Region(A2, B2, C2) and then fill down, Excel calls the function for each of the cells that the formula occupies and then puts the result in that cell.  It can take several seconds for all the cells to be populated, even with an i5 processor.  And the calculation can increase the drain on the battery if you’re doing this unplugged / on the road.

But when it’s complete, you can set up your Pivot Table with the regions in the row.  The average of the temperature values for Region A is shown in cell B5 below as 16.67.



Wednesday, November 01, 2017

Introduction to CLCL Tools

CLCL is the clipboard manager that I prefer.  But it’s lacking in extensive documentation, at least for those who don’t know Japanese.  I figured out how to configure the Tools that it comes with, so I thought I’d share that with you.

This procedure assumes that you already know how to download, install and run the main program.

Download the Tools from http://www.nakka.com/soft/clcl/index_eng.html .  There are two ZIP files (tltxt002_eng.zip and tlutl002_eng.zip, as of this writing) that provide DLLs with the functions that serve as tools.  Copy the DLLs from those ZIP files into the directory in which the CLCL executable resides.  While you’re at the Nakka website, you might as well download the other ZIP files that provide ability to manage as wider range of file formats.  Copy their DLLs, too.  As of this writing, there are two: fmtrtf002_eng.zip; fmtmeta002_eng.zip .

Invoke Tools from the Viewer menu, then choose Tool Setup…


Click the Add… button.

In the DLL textbox, enter the path and filename of one of the tool DLLs, for example, C:\Program Files (x86)\CLCL\tool_text.dll .  If you click the Browse button, you can use a File Dialog box to navigate to and select the DLL.

Now choose one of the Tools to add.  I find &Edit to be useful, so choose that.  OK your way back out.

Now when you press your hot key to call up the clipboard list, you can right-click on a text entry, then click on Edit to open a simple editor to modify the text.  When you’re done, you can click OK to put the edited content onto the clipboard, replacing the original entry.





Use the same procedure to try out the other tools.

Tuesday, October 31, 2017

Where Should You Stick Your Function?

Let's say you need to create a VBA function to use in a spreadsheet. Where do you put it? Quick answer, put it in a module.

In Excel, press Alt-F11, Ctrl-R (to set focus to the Project Explorer). Right click on VBAProject (xls_name), where xls_name in the file name of your workbook. Select Insert Module.

A blank code window should appear and the cursor should be positioned in it.  This is "Module1" where you can enter your code, such as...

Option Explicit
Function FortyTwo(r As Range)
If r.Value = 42 Then
    FortyTwo = "Forty-Two"
Else
    FortyTwo = r.Value
End If
End Function


If you enter 1, apple, and =6*7 in cells A1, A2 A3, here's what you get as output if you enter =FortyTwo(A1) in cell B1 and drag down to B3:







Of course, if A3 contained =6*9 you should also get Forty-Two, but that's a programming challenge for another day.

Sunday, July 02, 2017

The Dreaded Non-Disclosure / Non-Compete Agreement

If you work in the USA tech industry, you've probably been asked to sign a non-disclosure / non-compete agreement with a new employer.  It may be that even your current employer asked you to sign a new one.

If you're not familiar with it, let me describe it for you in a nutshell: Anything you witness or produce on company time becomes the property of your employer.  Even if you think of something, if you thought of it on company time, that idea is your employer's property.  This explains a lot of what I've observed during my career -- many coworkers are so poignantly aware of this that the second they clock in, they empty their minds completely of thoughts and go about their duties thoughtlessly.

If asked to sign a non-disclosure / non-compete agreement, what should you do?  This ebook from IEEE should help:
https://www.ieeeusa.org/members/IPandtheengineer.pdf

Good luck!

Sunday, June 04, 2017

Hard Drive Thrashing? Maybe It's Windows Update

In a previous post, I wondered if my computer problems were due to AntiVirus interfering with Windows Update.

Perhaps.  But there's definitely a problem with Windows Update. The following seemed to get rid of the excessive and endless thrashing of the hard drive:

http://www.cagedrat.com/microsoft-windows/microsoft-windows-updates-cab-files-filling-up-hard-drive/

And yes, I plug in my computer and set it to Stay Awake before downloading and installing updates.

Wednesday, May 17, 2017

Some Things Never Change

For over two thousand years, engineers had to contend with manufacturing issues.  We're still doing that today...

"... its design conception exceeded the engineering precision of its manufacture by a wide margin—with considerable cumulative inaccuracies in the gear trains, which would have cancelled out many of the subtle anomalies built into its design."

From the Wikipedia page "Antikythera mechanism," Google's feature for today, 2017-05-17.
https://en.wikipedia.org/wiki/Antikythera_mechanism

Sunday, April 23, 2017

Dummies Data Visualization Links

The following links are listed in Data Visualization for Dummies:

https://www.edwardtufte.com/tufte/
http://visual.ly/
http://chartporn.org/
https://excelcharts.com/posts/
http://flowingdata.com/

Seems to be more for artists than for engineers, though.

Thursday, March 30, 2017

A Better Way to Link to a Slide in PowerPoint

I've written about how to force Excel to use absolute paths in its links by specifying the Hyperlink Base  That works in PowerPoint, too.  Unfortunately, it interferes with PowerPoint's ability to follow internal links (links to other slides in the document).

Here's a workaround for that.  It allows you to link to another slide in the same PPT even if you have Hyperlink Base set to some location.  This was tested on PowerPoint 2003.

There are two parts to this.  The first part is to create a "bookmark" at the slide you want to link to.  Do this by creating a “Custom Slide Show”.  It's analogous to adding a bookmark in Word (but, regrettably much more complicated and less intuitive).
1.  In version 2003, choose Slide Show from the menu and then Custom Shows...
2.  Click the New... button.
3.  Enter a name for the Show in the uppermost textbox for the slide that you want to link to.  For example, you might enter "Detailed Analysis".
4.  In the left box, click on the slide that you want to "link to".  Then click the Add >> button.  (You can add multiple slides.)
5.  Click OK and then Close.

The second part creates the link to it.  When you click the link, it will run a mini slide show that consists of the target slide(s).
1.  Select some text that you'd like to make into a hyperlink, for example, "Please see the Detailed Analysis".
2.  Press Ctrl-K (or right-click on the selection and choose Hyperlink).
3.  Click "Place in this Document" on the left.
4.  In the scroll box that opens, scroll down to find "Detailed Analysis" (or whatever) under Custom Shows and click it.  (If you see only Custom Shows, click the plus sign to the left of it).
5.  Click the "Show and return" checkbox.
6. OK your way out.

The really neat thing is that the "link" persists even if slides are added before the target slide.  This is an awesome improvement over the conventional bookmark mechanism in which you're limited to linking to a slide number.  On the other hand, the hyperlink works only during a Slide Show.  There is no option to right click and open hyperlink.  So if you like to present in “edit mode” it won't work.

Also, navigation is a bit wonky.  When you click on the link, PPT will show the target slide, as expected.  But Alt-Left (the universal keystroke for "Back") doesn't return you to the previous slide.  In order to go back, you have to tell PPT to advance to the next slide (press PgDn, for example) to get back to the previous slide.  Pressing PgUp will cause PPT to ring the error bell at you.  Don't worry.  After a few dings, you'll get the hang of it.

Even if you don't need to set Hyperlink Base, you might prefer this method over the simpler method of linking to a slide.  Because if that slide's position changes, the simple link won't work the way you intended.

Let me know if you find this useful.  And if anyone knows this “GadiN” who reported the problem, please thank him or her for me and share this method.

Saturday, March 18, 2017

Is AntiVirus as Bad as Malware?

I've been using and recommending AVG AntiVirus Free for over a decade.  Whenever a new computer's trial version of Symantec AntiVirus would expire, I'd uninstall it and install AVG.

But when I accepted the upgrade to version 16, I lost the ability to control its update schedule.  It's no longer possible to disable automatic updates.  Now the only option is to accept automatic updates whenever they become available.  Users even lost the ability to force an update.

That's a big problem.  I once hosed a system when AVG updated during a Windows Update.  That was when I decided to disable automatic updates and run them manually with a simple right click of the taskbar icon.

I still have the install file for AVG 15.  Unfortunately, it downloads the full installer from the Internet and then installs the latest version.

I considered doing away with AntiVirus entirely.  But I'm not the only user of the computers -- the other users will need to have the safety net of an AntiVirus program.

So it's time to shop for a new AntiVirus program!

Friday, February 03, 2017

Adventures in Email Debugging

On Wednesday I was unable to download my personal email on my work computer.  Since downloading personal email at work is something I probably shouldn't be doing anyway, I didn't look into the matter right away.

And besides, my set up is a bit complicated, actually.  The email client is Outlook, which is used in IMAP mode to work with the Exchange email server.  But I also use Outlook to connect to Yahoo's POP and SMTP servers for my personal mail.  But not directly.

Outlook is configured to connect to Firetrust's Benign (0), which is set up to listen on a local IP address.  And Benign is configured to connect to POPFile (1).  So any one of those three programs could be at fault, or the Yahoo POP server could be down, or the IT department might've blocked the necessary ports.

I figured I'd restart my computer eventually.  But I was running a long script, and I didn't want to do a restart at that time.  So I first I stopped and restarted POPFile and then Benign.  And then Outlook.

When that didn't help, I fired up Firetrust's Mailwasher Pro (2), just to see if I could connect to the Yahoo POP server and download message headers.  I could.  So at least the POP port 995 (for SSL) was still open on the router.

Then I set up a new Outlook email account profile that would connect directly with the Yahoo mail server.  That worked, too.  So Outlook was still okay.  That meant Benign or POPFile was at fault.

I decided to check out the POPFile website first.  And there I read in the news listing, “The Windows version of POPFile 1.1.3 is no longer compatible with some SSL servers...”  True it was dated back to September 2015, but if Yahoo just upgraded its server, then it would make sense.

I downloaded and installed the SSL updater that POPFile provided (3) and got it all working again in a jiffy.

So if anyone else out there is using POPFile as an intermediary between Yahoo and his or her email client, be prepared to use this technique to get it working again.

(0) http://www.firetrust.com/products/benign
(1) http://getpopfile.org/
(2) http://www.firetrust.com/products/mailwasher-pro
(3) http://getpopfile.org/downloads/updateSSL-mk2-for-POPFile-1.1.3.zip

Saturday, January 14, 2017

On the Benefits of Social Media

Today's Soup to Nutz comic strip by Rick Stromoski is definitely blog worthy...
http://www.gocomics.com/soup-to-nutz/2017/01/14

If you can't follow the link, it's simply that Babs remarks to her brother Roy-boy,
I'm so glad I live in a time when there's social media...  In the old days it took weeks, even months...  before finding out that someone was an idiot."
Naturally I posted it to Facebook.

Saturday, October 29, 2016

Traffic Light Improvements For the Age of Mobile Communications

I have an issue with traffic lights.

When I'm stuck right behind an inattentive driver at a red light, I get annoyed when the driver doesn't go right after the light turns green.  I get infuriated when the driver waits so long to go that the light turns back to red again before I can get across the intersection.

That's pretty much the only time I use the horn.  And it occurred to me that the traffic light itself should be equipped with its own horn.  It would beep whenever it turns green, relieving other drivers of the effort of doing so.

Inattentive drivers annoy me even when I'm not behind them.  When they remain stopped at a green light while I'm at the red light for the crossing traffic, they cause the signal to take longer to cycle.  The light stays green longer for them and stays red longer for me.  I say aloud, “Go already, so I don't have to stay here forever!”

A few towns have installed traffic light cameras, which take a picture of the license plates of cars that go through red lights.  But I say that these cameras should be used to monitor the faces of drivers who wait at red lights.  Face recognition would be used to determine whether the driver is paying attention to the light, or whether they are reading e-mail or texting.  The light would stay red until the driver's gaze was focused on driving.

What do you think about this?

Friday, September 30, 2016

Presidential Candidates' Answers to the 2016 Top 20 Science and Technology Questions

For this election cycle, ScienceDebate has included the Green and Libertarian party candidates in its list of 20 questions regarding the most pressing "... Science, Engineering, Tech, Health & Environmental Issues in 2016."

You can read it all here: www.sciencedebate.org

Thursday, August 25, 2016

Fitting Data in Excel and OpenOffice Calc

I've stopped installing Microsoft Office onto my home computers. Instead, I installed OpenOffice on my latest two computers. It does everything I need it to do. Or so I thought.

One day I decided I wanted OpenOffice Calc to perform a polynomial fit to some measurements I'd been taking. So I did what I always do in Excel: create a Scatterplot of the data, add a Trendline, choose Polynomial and its order, and then click the checkboxes to display both the equation and the R2 value on the chart. Except there was no polynomial Trendline!

According to the OO help forums, there really is no built-in polynomial trendline in Calc. But there is an extension called CorelPolyGUI that does the trick.

Unfortunately, I wasn't too thrilled with this extension. My measurements were accumulating every week. With Excel, I'd be able to add new data and watch the scatterplot update the polynomial. But CorelPolyGUI doesn't work that way. The result from CorelPolyGUI essentially is a snapshot that's disconnected from the input data. To get it to update, I found that I had to delete the result and then re-invoke the extension with new data ranges. And that was a big problem – I wasn't sure over what extent of my data I wanted to fit. Perhaps I could get a better fit if I omitted some measurements. So I needed to alter the input range a few times and compare the results.

There is another method, that if you're clever, you can program yourself. It's based on the following set of equations (for a second-degree poly fit):



To get the values of A, B and C, you simply matrix multiply the vector on the left side of the last equation with the inverted 3 x 3 matrix on the right hand side. Once you program this into your spreadsheet, you can alter the data and instantly get the polynomial function to update.

But it turns out there's an even easier way. I found it accidentally in the results from my search for how to fit a polynomial in OpenOffice. It involves using LINEST to operate on array data. The web page^3 describes using LINEST in Excel to perform non-linear curve fitting. It turns out that the OpenOffice Calc LINEST function works the same way, albeit with slightly different syntax. And the syntax is different because of how you define an array in Calc, separating the elements with semi-colons instead of commas.

In retrospect, I see now the same solution in the OO help forums. The user Villeroy attached a spreadsheet with an example that uses LINEST. But instead of raising the range of independent values to {1;2}, he added the X2 column and referenced it in LINEST. Same thing, really, but perhaps a bit less elegant.

Wednesday, April 13, 2016

Must-Have Extensions For FireFox and Chrome

FireFox is my favorite browser.  It beats Chrome in terms of usability.  But I'm curious to see if I could live with Chrome for a while.  So I'm taking it for a test drive.

First for safe browsing, I like to have...
NoScript (FireFox) // ScriptNo/ScriptSafe (Chrome)
Blocks all scripts from running.  Allows the user to add exceptions for scripts on any given domain, either just for the current session (temporarily) or also for future sessions (permanently).  I think I like ScriptSafe on Chrome better than NoScript on FireFox.  Why?  Because NoScript will reload the page each time a single host is enabled, whereas ScriptSafe will let you enable multiple host before reloading the page.  And ScriptSafe features color-coded buttons while NoScript differentiates between temporary and permanent whitelist with italics.

WOT (FireFox) // WOT (Chrome)
WOT, or Web Of Trust, warns you in advance when a link leads to a dangerous website, before you even click on it.  The database of dangerous links is maintained by the community of WOT users.  But this sometimes can lead to sites getting blocked when a user disagrees with a site's ideology.  Still, you can get more detail on each website's rating and decide for yourself.


For usability, try these extensions...
FBPurity (FireFox, Chrome, Safari, Opera)
Facebook could be useful if only _______ (fill in the blank).  Well, FBPurity fills in the blanks by filtering out the elements that you don't want to see.  I use it to block "food pron" (plus other annoying and recurrent topics), to keep videos from auto-playing, to hide the reactions bar, to always sort posts in Most Recent order, to hide the newsfeed, etc.

LastTab (FireFox) // CLUT (Chrome)
N either FireFox nor Chrome cycle through tabs with Ctrl-Tab the way Windows cycles through active programs with Alt-Tab.  These extensions alter how these browsers behave when you press Ctrl-Tab.  So rather than cycling tabs from left to right, Ctrl-Tab cycles in Most Recently Used order.  There is one caveat, though.  Chrome extensions are not allowed to redefine default keystrokes (such as Ctrl-Tab), so none of the MRU-type tab managers on Chrome can fix Ctrl-Tab.  However, you can bind CLUT to Ctrl-q and Ctrl-Shift-Q, which is just to the right of Ctrl-Tab and Ctrl-Shift-Tab.

Password Management
Both Chrome and FireFox come out-of-the-box with the ability to remember the username and password needed to log in at each unique website.  However, FireFox can remember multiple usernames and passwords for any given site.  After looking for a Chrome extension to get Chrome to work this way (and failing), I thought I stumbled across an experimental option to enable the behavior.  But perhaps not, since the setting I thought I discovered doesn't affect this at all.  Rather, Chrome (at version 49) just started behaving the way I wanted it to!

View Selection Source
In FireFox, you can select content, right click on it and then choose a command to view the source code for that extension.  Chrome provides an "Inspect" command, but it reveals only the CSS details and not the complete HTML.  The View Selection Source extension for Chrome (or its equivalent) is necessary to see the snippet of HTML that's rendered by the browser for that selected content.  Yes, you can press Ctrl-U to view the source of the entire page in a new tab.  But then you have to search for the content you're interested in.  That's awkward, and it works only if the content can be pasted into the search bar.  The weird thing about the View Selection Source extension is that it doesn't come up if you search for it on Google Play.  I found the link in a post on the Help Center.

Save As... / Print To... PDF
Chrome has a built-in PDF printer that it calls "Save to PDF."  It works great, and there's no need to install a separate printer driver.  But you'll have to choose at least one of these three options to get FireFox to save a page as PDF, too.
  1. Install on your computer a PDF Printer Drive, such as PDFCreator or CutePDF.  (Both are free to download and use.)
  2. Install in FireFox a PDF printer extension.
  3. Use an online Web page to PDF service.
I like the first option, since the extensions I've come across either save the web page as a image or send the HTML over the internet to a server to perform the conversion.  I like the ability to select and copy text from the PDF, which is not possible with an image.  And when I generate PDF, it's usually to record a financial transaction, the details of which I'd rather keep on my local hard drive.

At one point I couldn't get the PDF printer drivers to work with FireFox.  Before giving up and switching to Chrome, I came across this Mozilla support page.  It turned out that resetting the print_printer setting fixed it.  As well, I've had to delete the prefs.js in order to solve a problem with the PDF coming out with all blank pages.

What are your favorite Extensions / Add-ons?


2016-07-09 LG Added the section "Save As... / Print To... PDF"
2016-06-13 LG Added "View Selection Source" paragraph.





Tuesday, April 12, 2016

Notes on Setting Up Windows 7

Recently I had to set up fresh installations of Windows 7 on two computers.  Here are some tips to make that process go a bit smoother...

1. Windows Update #1 -- Microsoft has released hundreds of recommended and important updates for Windows 7 since it was introduced.  All that data is a burden for Windows Update, and the update process can bog down on slower computers.  To remedy this, you'll want to download the update associated with KB3102810 first before you even check for updates.  Adjusting your computer's Power Options so it stays awake during the long update process may also help.

2. Windows Update #2 -- I wrote about this before.  Unless you want to upgrade to Windows 10, you'll want to hide the update KB3035583, or uninstall it if it already got onto your system.

3.  Gadgets -- Third party gadgets are no longer supported due to "serious vulnerabilities" in the Windows Sidebar.  You'll still be able to add the default Microsoft ones, such as "Clock," "Calendar," "Slide Show" and "CPU Usage" (my favorites).  But I also liked the third party "Network Meter," which I'd use often to verify download rates.  Since Network Meter is no longer available, I figured out that I can use ResMon to do something similar.  To have ResMon (almost) mimic Network Meter I minimize the various components in the left pane of ResMon and resize the window so that only the network graphs show up.  And I add a shortcut to ResMon.exe in my StartUp folder.

Do you have any tips for setting up Windows 7?  Please share them!

Saturday, March 26, 2016

Taking the Plunge

Several weeks ago I took the plunge and bought myself a cell phone.  This leaves my brother as possibly the only person in the USA who doesn't have one.

Many years ago I bought cell phones for both my wife and daughter.  But I scoffed at the idea of using one myself.  "No one wants to talk to me," I'd say.  As for emergencies, I'd say, "Everyone else has a cell phone.  I can ask someone to call for help."  And I could send texts via e-mail for free to my daughter's cell phone from my tablet.

So why get one now?  My motivation was not self-interest.  I got one so that my chronically-ill wife could get in touch with me easily in case she had a flare up.  As well, the tablet could send e-mail only when connected to a Wi-Fi network, so I'd have to struggle to find free public Wi-Fi in order to text my daughter.  Now that I have a cell phone, I can exchange texts with her wherever I happen to be.

Which cell phone did I choose?  Which plan?  Naturally, this Luddite was compelled to look for the cheapest and most basic phone and service.  But the Geek in me tempered that with technological requirements.  For example, since we already had two cell phones in use at our home, I looked for a device that would connect to the same (GSM) network.  I also wanted a device that could be charged through a microUSB port so that I could use a generic charger.  And I wanted push buttons, not a touchscreen.

I decided that for my needs, a pay-as-you-go plan would be far cheaper than a contract.  So I researched the plans and found out which providers used the network we were already using.  And I kept my eyes open at drug stores for those providers' phones.  And then I found a push-button phone, discounted 50%, for $4.99.  I bought it, despite the fact that I couldn't tell how it connected to its charger, and despite the nagging feeling that it was already obsolete.

Well, it turned out that it was obsolete -- I wasn't able to activate that $4.99 cell phone.  The company's customer service explained that the device wasn't supported in my area, and that they'd send a different one.  And the phone didn't have a microUSB, either. But I hoped that the replacement device would have one.

I waited, and I waited, for the replacement phone.  Finally, after two extra phone calls to customer service, which involved promises that I'd get it in two days, I got it.

They sent me an LG touchscreen phone.  I was initially disappointed about the touchscreen, but I tried to maintain an open mind.  "At least the device charges through a microUSB port," I told myself.  Also, this device had a "3x minutes, texts and data for life" plan associated with it.

It activated easily enough.  But something seemed wrong.  Every time I tried to make a phone call, the keypad would disappear from the screen as soon as the call connected.  So I wasn't able to "Press 1 for English" or anything like that.  (See, that's why I want a push-button phone.  Real buttons hardly ever disappear.)  Eventually, I figured out how to get the display to turn on.  If I held the power button down as if to turn off the phone, the screen would light up asking if I wanted to turn off the phone.  I could then respond "No" and gain access to the keypad without the phone disconnecting.

Even though I was able to use the phone, I decided that the phone was defective and needed to be replaced.  First, I visited the LG website and quickly found a customer service agent to chat with.  She "talked" me through the steps of rebooting the phone and then asked me to retest the phone.  It continued to misbehave, so she suggested that the proximity sensor was faulty and encouraged me to contact the provider to get the phone replaced.

I saved the chat text and sent it to one of the provider's customer service contacts, who again asked me to reboot the phone and try it again.  Finally, I got them to agree to send yet another phone, which arrived quickly and worked properly.

All of the sending and returning of phones, although time-consuming, was paid for by the provider.  I probably could have asked to have some minutes refunded because of all that I wasted while testing the phone, but I decided I was still ahead.

Eventually I bought more minutes and extended the activation period out 2 years.  I figured that the phone and service cost about $6 per month, assuming the phone lasts the entire two years.  So overall I'm pretty happy about it.  The only issue I have now is this: how do I carry the thing around all the time?

Wednesday, March 16, 2016

How About Never?

A coworker had just bought a refurbished computer with Windows 7 OS and was dutifully applying updates.  He noticed a new icon in the taskbar tray and clicked it.  The program presented him with the opportunity to upgrade to Windows 10.  It implicitly asked when would you like to download Windows 10?  The dialog box offered two buttons labeled "Upgrade now" and "Upgrade tonight."

How about Never?  That was not an option.

The Gwx.exe and GwxUX.exe programs make it easy for users to reserve their free copy of Windows 10.  They appear after the user applies the update associated with KB3035583.  And they disappear after the user uninstalls that update.

This "How To Geek" article describes it all in detail.

My previous post discusses why you might want to avoid upgrading.

Friday, July 31, 2015

The Windows 10 Giveaway

As of Wednesday Microsoft started giving away Windows 10.  What would you be giving away if you upgrade?  Privacy?  Security?  Performance? #UpgradeYourWorld

According to the Free Software Foundation1:
  • Windows' 10's privacy policy asserts the privilege to sell almost any information it wants about users, even creating a unique advertising ID for each user to sweeten the deal.
  • Microsoft announced that, starting with Windows 10, it will begin forcing lower-paying users to test less-secure new updates before giving higher-paying users the option of whether or not to adopt them.
  • Microsoft is reported to give the NSA special security tip-offs that it could use to crack into Windows computers.

"What am I supposed to do about it?" I hear you ask.

Close Windows, Open Doors
Close Windows, Open Doors


1 https://www.fsf.org/windows


Thursday, June 25, 2015

Undo the Default App Selection in Android

Here's the scenario....  Your Android device presents you with a choice of apps to complete an action with.  You're supposed to select the app and then select either "Just Once" or "Always."  Either way the app opens to complete the action.

If you selected "Just Once" you'll have to choose again the next time you need to complete that same action.  That might seem annoying.  But what if it's the wrong choice?  If you choose "Always" you won't get to choose again, at least not easily.  And if the app cannot complete the action successfully, what then?

According to many lame blog posts and webzine articles, it's "easy" to change your mind after choosing "Always."  They say to just press the app's "Clear Defaults" button.  Here's one such article on AndroidCentral.

Fortunately AndroidCentral is swarming with brilliant users who are much more sophisticated than the folks who write the articles.  I say "fortunately" because when I needed to change the option of using Photos for downloading an image file attachment, the article's advice was useless because Photos' "Clear Defaults" button was greyed out.

A user called Siddhartha Gupta suggested that to remove Photos as the default app, it's necessary to change the setting for Google+.  That didn't work, either.

A user called ChromeJob pointed out that there's "a 'reset app preferences' in the action overflow button. This appears to reset ALL default app choices at once."  If only it were that easy for me.  It didn't work.

The thing that finally worked for me was to revert to the factory version of Photos by pressing the "Uninstall Updates" button.  After doing that, I was presented with a choice of two other apps to use.  The idea to alter Photos' version came to me after reading a comment byGrillMouster who stated that "when any of those apps receive an update the ["Just Once" / "Always"] dialog will pop up again, even if you had previously set an app as the default."

If you want the very gory details of why Photos didn't work, please read on to find out what I was trying to do.

I had used Firefox to log in to an Exchange Server using an Outlook Web Access (OWA) client hosted on a web page.  I then opened an e-mail that had a JPG file attached to it.  When I attempted to download the attachment, OWA again wanted me to provide my username and password.  Photos was unable to handle that request (and neither was Firefox).  It was only by completing the action with ES File Explorer File Manager that I found out about the need to provide username and password.  I've included this detail in case there are others who are having trouble downloading attachments with OWA.

Saturday, June 20, 2015

My Recent Repair of a Laptop AC Adpater

Yesterday, my laptop wouldn't charge when I plugged it in.  The battery had drained overnight, so the laptop was unusable.  I quickly figured out that the AC adapter has suddenly stopped working.

My nearby Staples had a universal adapter in stock at 20% off, so I picked it up and was soon back in business.

But then I wondered why the "old" adapter had failed. The technician at Staples said that most fail due to a broken wire near the connector that plugs in to the computer.  I know that if you flex any wire enough that it will break.  But this computer was kept in the kitchen at home, and the cable stayed in one place most of the time.  I decided to take it apart and fix it.

Most of the repair guides for Laptop AC Adapters resolve a break or short in the wire at one of the ends of the DC cable.  One even recommends that you cut off the connector, and splice a new connector on, which is silly given that no casual user has a spare connector lying around.  This same guide says that if there's no voltage after cutting off the connector, the adapter is dead and you have to buy a new one.  Turns out, that's not true at all.

My repair approach was different.  I decided that I would crack open the adapter housing and then verify continuity from the circuit board to the connector with a DMM.  But as soon as I removed the housing, I saw the problem: Cold Solder Joints.  Whoever soldered the wires to the circuit board failed to thoroughly heat up both the pad and the wire.  So the solder didn't flow down the via hole and fully coat the wire.  This never would have passed inspection at my company.

I fired up my soldering iron and reflowed the three connections in less than two minutes.  It took at least five times longer for me to break open the housing.  Message to manufacturers of consumer electronics: If you won't bother to assemble the electronics properly, at least design the housings so that they're easy to take apart and put back together!  I glued it back together with RTV, and it's curing as I write this.

I've fixed several items with this type of reflow repair, including a fairly expensive audio receiver.  A soldering iron and the ability to use it can keep you from throwing out perfectly good electronics.

Tuesday, June 09, 2015

Free Excel Tutorial

I'm still using Excel 2003 at work.  It does all we need it to do.

And at home, Open Office's Calc is so compatible that I can forgo Excel completely, although I still use the Excel Viewer.

But there are some really neat features of the latest Excel.  I especially like Data Bars and Color Scales.

To learn more about them, I studied this Excel Tutorial from Udemy.

Some of the other tutorial sections were helpful, too.  For example, Pivot Tables have been updated.  What used to be Page Fields is now Filter.  And unlike Page, Filter allows you to choose more than one value.

Monday, April 27, 2015

Reverse the Order of Worksheets in an Excel Workbook

Today I found myself wanting to reverse the order of sheet tabs in an Excel file.  The VBA code snippet below does just that.

Sub Worksheet_Reverse_Order()
Dim MySheet As Worksheet
Dim i As Integer

For Each MySheet In Worksheets
Debug.Print MySheet.Index, MySheet.Name
Next

For i = 2 To Worksheets.Count
Set MySheet = Worksheets(i)
MySheet.Move before:=Worksheets(1)
Next i

For Each MySheet In Worksheets
Debug.Print MySheet.Index, MySheet.Name
Next

End Sub


Background...
I had been maintaining weekly status updates as Excel spreadsheets, all grouped into one XLS document.  Each week I'd add a new sheet to the right of the previous week's worksheet tab.

But due to a change in workflow, I now have to copy the new sheet into that workbook rather than create it in the workbook.  In order to keep placing the new sheet after all the others, it's necessary to scroll to the end of the list of sheets and select "(move to end)".

"It would be so much easier if the sheets were in reverse order," I sighed to myself.  The thought of dragging them into reverse order manually was, well, unthinkable.  And thus this VBA macro was born.

Sunday, October 12, 2014

When Flourescent Lights Go Bad

Fluorescent lights produce a lot of light for little power.  My kitchen lights, which use two T9 bulbs, are rated at 32W, 2400lm and 22W, 1400lm1.  The bulbs are expensive and not easy to find, but they supposedly last five years.

The problem is that the performance and longevity of fluorescent lights depends on the ballast.  This is an electrical module that conditions the current, and it's not 100% efficient.  Also the ballast will degrade and eventually need to be replaced.  Sometimes a faulty ballast makes itself evident when the light flickers, or when the light doesn't turn on immediately and you need to flip the light switch off and on to get it to light.  At this point the bulbs will burn out quickly.

The ballast is even more expensive and harder to find than the bulbs.  And replacing the ballast isn't meant to be done by the consumer, although a home owner who can replace a light switch or electrical outlet will be able to replace a ballast in about ten minutes if the fixture is designed well.

I mention all this because I again find it necessary to replace the ballasts in the two kitchen lights.  In fact, I was thinking of replacing these fixtures with new fixtures that have multiple sockets for standard (Edison screw) bulbs.  I figured this was a better long-range solution because it would allow me to use Compact Fluorescent Bulbs today and then eventually graduate to LED bulbs.  Never again would I need to search for the expensive ballasts and replace them.

But I did manage to find the ballasts for quite a reasonable price.  So it didn't make sense to replace them this time.  But in ten years, if I'm still in this house, I think I'll be buying new fixtures.


1 For a comparison of the lighting efficiency of various types of bulbs, please see https://en.wikipedia.org/wiki/Luminous_efficacy#Lighting_efficiency.

Thursday, August 07, 2014

Trials with an Old Computer

About six years ago, I mused about what to do with an old computer, a 500MHz Pentium III.  My idea was to reformat the hard drive (20GB) and install one of these operating systems: Windows 2000 (already obsolete); Windows XP (facing obsolescence); and Linux (Ubuntu, although I don't recall why I decided on that flavor).

I tried all three plus Dyne:bolic, a Linux variant specialized for music and video production on under-powered computers.  Here's how I fared....

Dyne:bolic was easy to try out, and I didn't have to reformat the Window NT drive to do it.  So I tried it first.  After downloading version 2, I burned the ISO image to a CD.  It booted up just fine and I ran it from the CD.  It performed well, but it was set up for a single root-level user, and it wouldn't "play" Flash content.

Next was XP.  The first problem I had was that I couldn't activate the OS, even though I had a valid key.  But I played around with it anyway during the evaluation period.  Just twenty minutes was enough to know it would be way too slow.

Then I installed Windows 2000.  This involved a lot of tedious business with multiple CDs for the OS itself, then Service Pack 6 and then more CDs with security software and utilities.  Everything went well until I installed the antivirus program and updated it.  After that, the OS would not start.

Finally I decided to give Linux a try.  Rather than download images files, I decided to search the local public library system for Linux books that had accompanying CDs.  And I limited my search to old books, too, since I really needed the installer to be on CD-ROMs and not a DVD.  There were some Red Hat Linux books, so I got one and tried it.  It installed and ran really well except for the web browser, Mozilla, which had me pressing Ctrl-Alt-Del and longing for Task Manager to come up so I could kill it.

Of these four options, Dyne:bolic was clearly the best.  Unfortunately, by the time I got around to realizing it, Jaromil released version 3.0.0, whose 1.6GB image now must be burned onto DVD, not CD.  (I can't find the CD that had version 2 on it. And booting from USB is not an option in this computer's BIOS.)  This latest Dyne:bolic is totally awesome -- I tried the Live CD on my main home desktop (a P4), and I created a small virtual machine on my work computer, which boots the image file.

In order to run D:B3 on my PIII, I need a DVD drive.  Since I had two on my main desktop, I removed one and installed it on the PIII.  But, alas, it didn't work.  The computer detected the drive, but it won't boot from it, and Linux won't mount it.  So I think the laser is shot.  I've encountered a few non-functioning DVD drives in this manufacturer's computers, so I really do think the drive is defective.  In fact I wasn't able to boot from the drive recently when it was in the P4 that I took it out of.

So this is where I am now.  I need a working IDE DVD drive, which are expensive and/or refurbished.  There are adapters that can convert a SATA drive to IDE, but that's an extra expense I didn't want to pay.  Plus, I'm not sure this small form factor case will have any room for it, although I can put the new SATA drive with IDE adapter into the main desktop and move the working IDE DVD drive from the main desktop to the PIII if I really had to.

If / when I clear this hurdle I'll check in again.  Hopefully D:B3 will still be available!

Sunday, July 06, 2014

Creative Door Repair

The back door of our home never quite opened and closed smoothly. It was necessary to lift the doorknob while closing it in order to prevent the bottom from scraping the threshold.

Very recently the upper hinge pulled completely away from the door frame.  My wife and daughter couldn't finesse the door closed any more.  I re-tightened the screws, but the holes for the screws had widened, so the screw threads no longer had enough wood to bite into.  The hinge wouldn't stay secure for long.

My first impulse was to replace the screws with longer ones of the same diameter.  But not finding any in my collection, I realized I would have to visit the hardware store.

I really enjoy going to the hardware store.  Not the big, nation-wide chain stores like Home Depot or Lowes, though.  I prefer the small, neighborhood shops that seem to carry the odd-ball bits of fixture parts that were used in our neighborhood over fifty years ago when our homes were built.  Our stores are usually staffed by a retired handyman or engineer.  Or maybe the guy just likes hanging out there, giving out free advice without even getting paid for it.

Alas I was too busy to make the trip.  So I busied my mind, thinking of alternative repair options while carrying out the many tedious chores I had to deal with.

My next idea was to plug the screw holes with wooden dowels.  In fact I had many ¼ inch dowel pins left over from an old wood-working project.  I could use those.  But because they were much larger than the screws and the holes, I'd have to drill out the holes first before inserting the pins.  And then I'd have to drill pilot holes into the dowels themselves so that I could get the screws into the pins.  And I'd probably have to use carpenter's glue to hold the dowel pin in place before drilling.

If I had much smaller dowels, I could simply stick them into the holes and jam the screws in.  This would certainly be enough to keep the screws fastened tightly.  But because I didn't have the smaller dowels, I'd have to go to the hardware anyway.

Finally the solution came to me.  I had all the dowels I needed right outside my door!  All I had to do was stroll through the wooded area of our yard to find the right size twig.  Which I did.  It took about 30 seconds.

One oak twig about four inches long was enough to fill all four screw holes.  I broke the twig into four pieces and inserted them into the holes and tightened the screws.

And now the door opens and closes easily, without needing to be lifted, and without scraping the bottom.

This to me is what makes home repair an art form.

Friday, June 13, 2014

Execute Text in MS Word Using the System Shell

I was writing a tutorial in Microsoft Word that describes commands that the reader is supposed to enter at the command prompt.  I thought it would be neat if I could run those commands from within Word to validate them as I entered them.

And so I came up with a surprisingly simple VBA subroutine that sends selected text to the shell.  It is quoted, below.  The code should be placed into a module in Normal.dot.

Note that I invoke two statements in the Shell.  They are separated by the double ampersands.  I combine them into a single string (strCmd) that I pass to the shell.

The first statement is to change to the current working directory, which I assume is the same directory that the Word document resides in.  This isn't fool proof, however.  One failure mode would be if someone were to start Word and create a new document without saving it to the hard drive before calling the routine.  Another failure mode would be if the Word document were to reside on a remote share through a UNC path, such as \\FileServer\ShareName\tutorial.doc -- it's not possible to CD into a UNC path.

The second statement is merely the selected text.

Also note that strCmd  is preceded by the Win32 command prompt CMD.EXE.  The "/D" switch makes sure that no "AutoRun" commands get executed.  The "/C" switch terminates CMD after the command is finished executing.  CMD is included because Shell isn't able to find DOS commands such as CD.

Sorry for the small font on this source code, but I wanted to ensure it wouldn't wrap.

Sub InvokeWithShell()
' Executes the selected text to using the shell
' 2014-06-09 LudditeGeek Created
    Dim strCmd As String
   
    If Selection.Characters.Count <= 1 Then
        MsgBox "Nothing Selected!", vbExclamation, "Invoke With Shell Macro Message"
    ElseIf Selection.Paragraphs.Count > 1 Then
        MsgBox "Multiple Lines Selected!", vbExclamation, "Invoke With Shell Macro Message"
    Else
        strCmd = Selection.Text
        Debug.Print "Invoking " & strCmd
        strCmd = "cd " & ActiveDocument.Path & "\ && " & strCmd
        Shell "cmd /D /C " & strCmd
    End If
   
End Sub

Saturday, March 01, 2014

Blackphone and Webroot

Friday on NRP, Morning Edition featured the Blackphone, a smart phone with privacy as its number one priority.  Also mentioned were Black, Boeing's super secure smart phone, and Webroot, a security application.

Read more at http://www.npr.org/blogs/alltechconsidered/2014/02/28/283523473/a-smartphone-that-tries-to-slip-you-off-the-grid.