SINGAPORE EXPATS FORUM
Singapore Expat Forum and Message Board for Expats in Singapore & Expatriates Relocating to Singapore
Discuss about computers & Internet. Including mobile phones, home appliances & other gadgets. Read about Windows security risks or virus updates.
2 posts • Page 1 of 1
Hi,VBA inquirer wrote:What is the command to convert a string into a command? Preferably in the excel's cell.
Cut and paste the following code into an Excel VBA module.
Put the command you want to run into Cell B2.
Run the subroutine, and voila!
Code: Select all
Option Explicit Private Declare Function ShellExecute Lib _ "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation _ As String, ByVal lpFile As String, ByVal _ lpParameters As String, ByVal lpDirectory _ As String, ByVal nShowCmd As Long) As Long Const SW_HIDE = 0 Const SW_SHOWNORMAL = 1 Const SW_NORMAL = 1 Const SW_SHOWMINIMIZED = 2 Const SW_SHOWMAXIMIZED = 3 Const SW_MAXIMIZE = 3 Const SW_SHOWNOACTIVATE = 4 Const SW_SHOW = 5 Const SW_MINIMIZE = 6 Const SW_SHOWMINNOACTIVE = 7 Const SW_SHOWNA = 8 Const SW_RESTORE = 9 Const SW_SHOWDEFAULT = 10 Const SW_MAX = 10 Sub RunACommand() Const CellContainingTheCommand = "B2" Dim TheCommandToRun As String Range(CellContainingTheCommand).Select TheCommandToRun = ActiveCell.Text ShellExecute 0&, vbNullString, TheCommandToRun, _ vbNullString, vbNullString, SW_SHOWDEFAULT End Sub
Users browsing this forum: No registered users and 2 guests