Allocate the "User" variable in the path of the folder where Excel is located
Guys, good afternoon!
I just migrated to Office 365 with the entire server in the Cloud. The code below worked normally, as the main worksheet was on a physical server and the path of this file in Excel was fixed for any user who was logged on the network and on any machine connected to the network, but with the migration to the cloud, the path of the same became dynamic by One Drive through the username active on the computer.
I created the following subroutine to capture the active user on the machine and allocated it to a variable that worked when I printed a test message on the screen, as below:
Sub GetActiveUserNameAndSavePDF()
Sub GetActiveUserName()
Dim UserName As String
UserName = Environ("UserName")
Dim User As String
User = UserName
End Sub
The following code is what searches for all active information on the screen and saves it as a PDF in the folder that used to be on a physical server. I tried to allocate the variable in the path (highlighted in " & User & "), but it doesn't work, the path is not found:
Private Sub CommandButton1_Click()
ActiveWindow.SmallScroll Down:=-9
ActiveSheet.Range("A1", "K30").Select
ActiveWindow.SmallScroll Down:=-42
ChDir "C:\Users" & User & "\Unimed FDRJ\OCA - Documentos\trab\pac\Cardiologia\Prints" '<<<<<< ALTERAR O CAMINHO DE SALVAMENTO'
ThisWorkbook.Worksheets(Array("Autorização")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users" & User & "\Unimed FDRJ\OCA - Documentos\trab\pac\Cardiologia\Prints - " & Range("B9") & " - " & Range("B11") & " - Senha " & Range("J7") & " (" & Range("C13").Value & ")"
ActiveWindow.SmallScroll Down:=-3
End Sub
Can you help me? thanks!