Hi, I am very new to VBA in Excel and need some help figuring out how to accomplish this. So I have data in A2 to A100 and I want to run the below code when I double-click on the each cell in that range. It should run the same VBA code.
The code below the double click event basically takes the contents of A2 and copies it into a text file on my C:\ drive. I want to update this text file every time I click on a different cell.
Any help would be great!
The code below the double click event basically takes the contents of A2 and copies it into a text file on my C:\ drive. I want to update this text file every time I click on a different cell.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A2:A100")) Is Nothing Then
Dim oShell As Object
Set oShell = CreateObject("WSCript.Shell")
Dim myFolder As String
Application.DisplayAlerts = False
ActiveSheet.Activate
Range("A2").Select
Selection.Copy
'This temporarily adds a sheet named "Test."
Sheets.Add.Name = "Test"
Sheets("Test").Select
ActiveSheet.Paste
'Save selected data as text file in users selected folder.
ActiveWorkbook.SaveAs Filename:="C:\work\imagepo.txt", FileFormat:=xlText, CreateBackup:=False
'Remove temporary sheet.
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'Indicate save action.
MsgBox "Text File: " & myFolder & "Saved!"
'Go to top of sheet.
Range("A2").Select
Application.DisplayAlerts = False
Application.Quit
End If
End Sub
Any help would be great!