So I have an interesting situation that I have ran into a wall on. When the macro is run in the VBA screen, I have zero errors. When I use a button (shape) located in the worksheet, exactly every other time I get a 400 error.
I've tried to use a "launching" macro that calls the main macro and added a simple message saying the macro is done. Same issue with ever other launch of the macro giving a 400 error.
I've tried setting a breakpoint on Sub map_q_drive_from_SP() and the error occurs before it gets to the breakpoint.
The code is launching a .BAT file. If I try putting the .BAT on a server location, no issue. When it is on the SharePoint site, that's when it errors 400. The .BAT file does work on SP and that is where the final home needs to be for it.
Any ideas?
Thanks,
Mike
I've tried to use a "launching" macro that calls the main macro and added a simple message saying the macro is done. Same issue with ever other launch of the macro giving a 400 error.
I've tried setting a breakpoint on Sub map_q_drive_from_SP() and the error occurs before it gets to the breakpoint.
The code is launching a .BAT file. If I try putting the .BAT on a server location, no issue. When it is on the SharePoint site, that's when it errors 400. The .BAT file does work on SP and that is where the final home needs to be for it.
Any ideas?
Thanks,
Mike
Code:
Sub map_q_drive_from_SP()
Dim user_name As String
Dim total As Integer
Dim Result() As String
Dim strFolderName As String
Dim strFolderExists As String
On Error Resume Next
'Sets the username for access to SharePoint
bat_file_location = "C:\Users\username\OneDrive - HNI Corporation\Veneer Plan List\Industrial Eng Analysis Tools"
user_name = VBA.Interaction.Environ$("UserName") 'Currently Logged In User Name
'default value
current_section = 0
'----------
Result = Split(bat_file_location, "\")
total = UBound(Result())
Do Until current_section > total
section_value = section_value & Result(current_section)
If current_section = 2 Then
section_value = section_value & "\"
current_section = current_section + 1
ElseIf current_section = 0 Then
section_value = Result(current_section)
section_value = section_value & "\"
current_section = current_section + 1
ElseIf current_section = 1 Then
section_value = section_value & "\" & user_name & "\"
current_section = current_section + 2
ElseIf current_section = total Then
section_value = section_value
current_section = current_section + 1
Else
section_value = section_value & "\"
current_section = current_section + 1
End If
Loop
bat_file = section_value & "\Drive.BAT"
'Check SharePoint connection
strFolderExists = Dir(bat_file, vbDirectory)
If strFolderExists = "" Then
MsgBox "Cannot map the Q:\ drive." & Chr(13) & Chr(13) & "Check your connection to SharePoint" & Chr(13) & Chr(13) & "\\Waygnl-flpin01p ", vbExclamation, "CANNOT MAP Q:\ DRIVE"
End
Else
On Error GoTo end_macro
ThisWorkbook.FollowHyperlink Address:=bat_file, NewWindow:=True 'Open Website
End If
'MsgBox section_value & "\Drive.BAT"
end_macro:
End Sub