Excel VBA - Passando um caminho variável com espaços para a linha de comando do WinSCP
Eu tenho o código na parte inferior deste post em um dos meus livros de excel (minha primeira vez escrevendo código vba). O objetivo aqui é permitir que os usuários:
inicie uma codificação de vídeo usando o software MXLight com um nome de arquivo temporárioselecione uma célula com a pessoa atualmente em vídeointerrompa a codificação do vídeo, renomeie o arquivo temporário, mova-o para uma pasta específica, faça o upload via FTP via software WinSCP, marque-o em verde, mova uma célula para baixo.Então, durante o evento, você:
Pressione o botão 1, que é o Sub StartMXLentão você destaca seu celularPressione o botão 2, que é o Sub StopAndProcessMinhas perguntas são as seguintes:
1) Em primeiro lugar, o botão inteiro (parar e processar) não funciona porque a função de upload falha, porque não consigo descobrir como obter o comando winscp para usar a variável referenciada ... e não tentar literalmente use essa palavra. Verifique o código no Sub Upload, e aqui está o arquivo de log quando tento isso:
1 . 2015-11-12 17:53:18.490 Connected
2 . 2015-11-12 17:53:18.490 Using FTP protocol.
3 . 2015-11-12 17:53:18.490 Doing startup conversation with host.
4 > 2015-11-12 17:53:18.491 PWD
5 < 2015-11-12 17:53:18.520 257 "/" is the current directory
6 . 2015-11-12 17:53:18.520 Getting current directory name.
7 . 2015-11-12 17:53:18.520 Startup conversation with host finished.
8 < 2015-11-12 17:53:18.520 Script: Active session: [1] [email protected]
9 > 2015-11-12 17:53:18.520 Script: put RealFile
10. 2015-11-12 17:53:18.520 Copying 1 files/directories to remote directory "/"
11. 2015-11-12 17:53:18.520 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
12. 2015-11-12 17:53:18.520 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
13. 2015-11-12 17:53:18.520 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
14* 2015-11-12 17:53:18.520 (EOSError) System Error. Code: 2.
15* 2015-11-12 17:53:18.520 The system cannot find the file specified
Você pode ver na linha 9 que está tentando literalmente fazer upload do arquivo chamado "RealFile" em vez de usar o conteúdo da variável com o nome do arquivo e a estrutura da pasta. Essa variável está funcionando em outras partes do código, como quando estou renomeando e movendo-a.
Alguma idéia aí?
Aqui está o código total para a coisa toda:
Public Sub StartMXL()
Dim MXLapp As String
MXLapp = "C:\1a7j42w\MXLight-2-4-0\MXLight.exe"
Shell (MXLapp & " record=on"), vbNormalNoFocus
AppActivate Application.Caption
End Sub
---
Public Sub StopMXL()
Dim MXLapp As String
MXLapp = "C:\1a7j42w\MXLight-2-4-0\MXLight.exe"
Shell (MXLapp & " record=off"), vbNormalNoFocus
AppActivate Application.Caption
End Sub
---
Sub ChooseRootDir()
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please choose a folder"
.AllowMultiSelect = False
If .Show = -1 Then Sheets("rawdata").Range("I1").Value = .SelectedItems(1)
End With
End Sub
---
Public Sub RenameAndMove()
Dim TempFile As String
Dim RealFile As String
If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value, vbDirectory)) = 0 Then
MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value
End If
If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value, vbDirectory)) = 0 Then
MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value
End If
If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value, vbDirectory)) = 0 Then
MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value
End If
TempFile = Sheets("rawdata").Range("I1").Value & "\tempfile\spiderman.TS"
RealFile = Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value & "\" & ActiveCell.Value & ".TS"
Name TempFile As RealFile
End Sub
---
Public Sub Upload()
Dim RealFile As String
Dim TempFile As String
RealFile = Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value & "\" & ActiveCell.Value & ".TS"
TempFile = "C:\1a7j42w\MXLight-2-4-0\recordings\tempfile\spiderman.TS"
Call Shell( _
"C:\1a7j42w\WinSCP\WinSCP.com /log=C:\1a7j42w\WinSCP\excel.log /command " & _
"""open ftp://ftp1934501:[email protected]/"" " & _
"""put RealFile"" " & _
"""exit""")
End Sub
---
Sub StopAndProcess()
Call StopMXL
Call RenameAndMove
Call Upload
Selection.Interior.ColorIndex = 4
ActiveCell.Offset(1, 0).Select
End Sub