How to view the query the SQL for an Excel worksheet with data source

 

Save the following code in a module.

Sub print_query_table_sql()
    Dim s As Worksheet
    Dim qt As QueryTable
    Dim r As Range
    Dim sql As String
    Set s = ActiveSheet
    Set qt = s.QueryTables(1)
    sql = qt.sql
    Set r = s.Cells(1).SpecialCells(xlLastCell).Offset(1, 1)
    r = sql
End Sub

 

Select your worksheet that contains data from a database source, then run the above macro.

It will print out the SQL in the last cell. (Ctrl-End).

Technorati tags: ,

Synergy failed to connect to server: address not found for

imageFor a while just now, Synergy did not work for me. On the status window, I see these error messages "failed to connect to server: address not found for <my computer name>"

Restarting Synergy on both server and client did not fix the issue.

Finally, I found that the Computer Browser service on the server (<my computer>) was disabled. After I started the service, Synergy worked again.

Technorati tags:

Sharing/transferring files – a brief history of how we did it before My Wifi

I have been using PCs/notebook for a pretty long time.

When I was in school (in the 1980s), to transfer files between two PCs, I had to copy the file onto a floppy drive, then use the other PC to read the floppy drive.

That was obviously a major pain if there are a lot of files and the files are too big to fit onto a floppy.

Luckily, later in the workplace (around 1990s), we could use laplink cables to connect between 2 PCs and transfer files between them. Networking in the office at that time was still not common and the laplink cables were connected to some port (I forgot whether they were serial or parallel port)

Then networking became more common and we can just share filles between computer over a network. And if we were somewhere without a network, we had several alternatives:
1. the USB thumb drive which though smaller than the floppy had bigger capacity.
2. infra red – my notebook in the early 2000s had a infra red port that I could point to another notebook also with an infra red port and both of us could transfer files. It was slow and there must be a direct line of sight between the 2 infra red points.

My next notebook after the infra red notebook came with Bluetooth but not infra red.
With Bluetooth, it was slightly faster and I could share with several Bluetooth notebooks at once.

The next evolution in sharing files ? Intel just came up with My WiFi technology.

Direct2Dell – Direct2Dell – DELL COMMUNITY

Last week, we introduced My WiFi technology as an option on the Dell Studio 15, Studio 17 and the Studio XPS 16 laptops to customers around the world.

Cookie
Cookie

Upgrading from Python 2.5 to Python 2.5.4

I was hesitant to upgrade from Python 2.5 to 2.5.4 on because upgrades usually break something.

I tested it first on a desktop. The default upgrade installed to a C:\Python25 directory and a lot of things broke. Python scripts that worked before stopped working.

easy_install would not work because it could not find Python.exe.

This was due to my previous Python installation was on c:\1Programs\Python.

Fortunately I created a system restore point before the upgrade and I restored to the point.

At this time, Python was still not working properly – the restore did not repair everything. So much for Window’s System Restore.

Then I installed Python 2.5.4 again, this time on c:\1Programs\Python.

Now, everything works!

Lessons learnt:

1. Test the upgrade on a test machine first

2. Install upgrades on the same path of the original installation

3. Don’t count on Window’s System Restore Points

Vim compiled with Python 2.5

You might want Vim compiled with +python if you’re trying to get Vim’s wonderful omnicomplete to work.

The gvim.exe at vim.org does not have +python for 2.5.

You can get a python 2.5 build at Yong Wei’s site.

image

Now omnicomplete works for me !!

Scheduling Python scripts as Scheduled Tasks

When scheduling python scripts as Scheduled Tasks in Windows, take note that although you specify the script with arguments eg :

kl_ofm.py -g -v

When the scheduled task runs, it runs as kl_ofm.py without the arguments.

The above is something to take note of when scheduling Python scripts.

 

One option around this is to put kl_ofm.py -g -v into a batch file and schedule the batch file as the job to run.

Running Scheduled Tasks from the command line

The command is schtasks /run /tn <taskname>

However the taskname must not contain ‘.’. If it does, rename it

C:\1\python>schtasks /RUN /TN "kl_obo_uploader.py"
ERROR: The parameter is incorrect. 

After renaming,

C:\1\python>schtasks /RUN /TN kl_obo_uploader
SUCCESS: Attempted to run the scheduled task "kl_obo_uploader".

Python programming with Excel, how to overcome COM_error from the makepy generated python file

import win32com.client
 
xl = win32com.client.Dispatch('Excel.Application')
wb = xl.Workbooks('Book1')
ws = wb.Worksheets('Sheet1')
cell = ws.Range('A1')
cell.SetValue(arg1 = 'test entry in Excel')

 

Above is a very simple python script to write something in Excel.

To run the above, you need Mark Hammond’s pywin32 to generate the PythonCOM package. Read O’Reilly’s Python Programming on Win32 for more information on what PythonCOM packages are.

Once you have installed pythonwin, start it and generate the python code for Excel like this:

image

1. Start PythonWin

image 

2. Select MakePy

image

3. Select the Excel library

image

4. The python file is generated.

image

However, the generated file will not yet work. If you now type in the above code snippet, you will get an COM error:

com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -214735
2565), None)

The cause of the com_error is various, on one machine, it was due to some bug in the file.

Use your editor and open the generated python file, find all the ret = Dispatch lines …

ret = Dispatch(ret, 'Item', '{00020857-0000-0000-C000-000000000046}', UnicodeToString=0)

and replace with

ret = Dispatch(ret, 'Item', '{00020857-0000-0000-C000-000000000046}')

On another, it was because xl was linked to an Excel instance which was visible. I did this to make it show itself

xl.Visible = 1

 

Technorati tags: ,

Anticipating my next Dell with Windows 7

Lifehacker – Windows 7′s Best Underhyped Features – windows 7

Windows 7′s Best Underhyped Features

As I mentioned why I want to get another Dell, I am looking forward to Windows 7.
The more I read of Windows 7 features, the more I like it.
However, I hope the following application will still work on Windows 7
1. Launchy – the ultimate application launcher
2. Texter – a great keystroke saver
3. Synergy – indispensable for working with multiple computers
4. AutoHotkeya great application for recording keystrokes, repetitive keystrokes or writing macro


Finding the last query in Oracle Applications

oracle applications last query 

1.) Goto Help
2.) Click on Diagnostics
3.) Then Examine
4.) In the first field (block) enter SYSTEM
5.) For Field enter LAST_QUERY
6.) Then click on Values
7.) You will see last query

Pages:«123456»