Right vba coding while delaing with userform buttons

41 Views Asked by At

Below code works well in a different module but it doesn't if used for a userform button. It doesn't print the content of the file in immediate window.I request a correction or guidance. Thank You

Private Sub UploadBut_Click()

Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
Dim P As String

'BrowseFile.Value is a text box in my UserForm which captures path of the file

If BrowseFile.Value = "" Then
MsgBox "Please Select File", , "Upload File"
Else
On Error Resume Next
P = Chr(34) & BrowseFile.Value & Chr(34)
TextFile = FreeFile

FilePath = P
FileContent = Input(LOF(TextFile), TextFile)
Debug.Print FileContent

Close TextFile
End If

End Sub
1

There are 1 best solutions below

0
On

Oh my god ! How silly I am. I just removed Chr(34) (quotes) and it worked.