The goal of my macro is to prompt user to select a cell, then read this cell's value and assign it to a string variable.
This is my code:
Sub update_custdb_from_id_number_to_the_right()
Application.ScreenUpdating = False
'Application.DisplayAlerts = False
Dim wordApp As Word.Application
Dim wordDoc As Word.Document
Dim excelApp As Excel.Application
Dim mySheet As Excel.Worksheet
Dim Para As Word.Paragraph
Dim wordRng As Word.Range
Dim fullName As Word.Range
Dim exclRng As Excel.Range
Dim scndRng As Excel.Range
Dim pStart As Long
Dim pEnd As Long
Dim Length As Long
Dim startPos As Long
Dim endPos As Long
Dim parNmbr As Long
Dim x As Long
Dim flag As Boolean
Dim sCell As String
Dim intRow As Integer
'Assigning object variables and values
Set wordApp = GetObject(, "Word.Application")
Set excelApp = GetObject(, "Excel.Application")
Set wordDoc = wordApp.ActiveDocument
Set mySheet = Application.ActiveWorkbook.ActiveSheet
Set wordRng = wordApp.ActiveDocument.Content
Set scndRng = ActiveSheet.Range("A1")
sCell = ActiveWorkbook.ActiveSheet.Range(Application.InputBox(Prompt:="Pick the Cell", Type:=8)).Value 'sCell = Range(Application.ActiveWorkbook.ActiveSheet.InputBox(Prompt:="Pick the Cell", Type:=8)).Value
' Application-defined or object-defined error
sCell = Trim(sCell)
Debug.Print sCell
intRow = 1
x = 11
End Sub
While running this macro I get Application-defined or object-defined error
in sCell = ActiveWorkbook.ActiveSheet.Range(Application.InputBox(Prompt:="Pick the Cell", Type:=8)).Value
line. I press F8 to debug the line above and the InputBox
appears.
I then type B4 or B6 into the InputBox
and when I press OK the Application-defined or object-defined error
. appears.
Looking 4 solution I've read this thread thread because this line previously was returning the Run-time error '1004' : Method 'Range' of object'_Global' failed
error, so I've changed it a bit and now it's giving me this Application-defined or object-defined error
.
What do I need to write to prompt user to select cell during macro execution and later assign this cell's value to a string variable.
Last thing is to Debug.Print sCell
into the immediate window.