What is the command to convert a string into a command?
Preferably in the excel's cell. Thanks in advance.
SINGAPORE EXPATS FORUM
Singapore Expat Forum and Message Board for Expats in Singapore & Expatriates Relocating to Singapore
Executing string as command in VBA/Excel
Re: Executing string as command in VBA/Excel
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
Who is online
Users browsing this forum: No registered users and 1 guest