본문 바로가기
  • Welcome!
VBA VB.Net Code

Select the file name in the cell and open it

by ToolBOX01 2024. 9. 11.
반응형

□ Main Code

Sub GetSelectedCellValue()
    Dim selectedObject As Object
    Dim cellValue As Variant

    On Error GoTo ErrorHandler

    '// Save the user selected object to a variable
    Set selectedObject = Selection

    '// Check if the selection is a single Range
    If TypeOf selectedObject Is Range And selectedObject.Areas.Count = 1 Then
        '// Get the value of the selected cell
        cellValue = selectedObject.Value

        '// Display warning message if cell value is empty
        If IsEmpty(cellValue) Then
            MsgBox "The selected cell is empty"
            Exit Sub
        End If

        '// Output the retrieved value to a message box
        MsgBox "The value of the selected cell is " & cellValue 
    Else
        MsgBox "Please select only a single cell."
        Exit Sub
    End If

Exit Sub

ErrorHandler:
    MsgBox "형식이 일치하지 않습니다. 다시 시도해주세요."
End Sub