比方说,我在Excel列BD中有一个文件路径列表。如何使用VBA命令选择BD列中的所有文件路径并将其保存到我想要的任何位置?
我找不到与此有关的任何教程。
这是最近的:
https://www.youtube.com/watch?v=pHFucY4VMT4
但是我认为这仅限于excel和特定的文件路径。
在这里感谢任何易于使用的代码建议! VBA的新手,所以请不要对我造成太大的伤害:P
P.S我尝试了此操作,但收到错误消息:
Private Sub CommandButton8_Click()
Option Explicit
Sub CopyFiles()
' (1) requires a reference to the object library "Microsoft Scripting Runtime" under Options > Tools > References in the VBE.
Dim FSO As Scripting.FileSystemObject
Dim DesPath As String
Dim C As Range
Dim LastRow As Long
Set FSO = New Scripting.FileSystemObject
'your destination path
DesPath = "C:\"
With ThisWorkbook.Sheets("MySheet") 'change MySheet for your sheet name
LastRow = .Cells(.Rows.Count, "BD").End(xlUp).Row 'last row on column BD
For Each C In .Range("BD2:BD" & LastRow) 'loop through all the cells from 2 to LastRow
If Not C = vbNullString Then 'check that the cell isn't blank
FSO.CopyFile C.Value, DesPath, True 'True means overwrite
End If
Next C
End With
End Sub
我收到的错误消息是“编译错误:内部过程无效”
此错误以黄色突出显示此VBA命令: “私人子CommandButton8_Click()”
答案 0 :(得分:0)
您可以像这样使用FileSystemObject:
onMessage = (e) => {
// retrieve event data
let data = e.nativeEvent;
console.log('data', data);
// maybe parse stringified JSON
try {
data = JSON.parse(data);
} catch (e) { }
// check if this message concerns us
if (typeof data === 'object' && data.external_url_open) {
// proceed with URL open request
console.log('external_url_open', data.external_url_open);
// Linking.openURL(data.external_url_open);
this.openSocialNetworksURL(data.external_url_open);
}
}
openSocialNetworksURL = (url) => {
Linking.canOpenURL(url).then((supported) => {
if (!supported) {
console.log(`Can't handle url: ${url}`);
} else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));
}
render() {
const injectedJs = '!function(){var e=function(e,n,t){if(n=n.replace(/^on/g,""),"addEventListener"in window)e.addEventListener(n,t,!1);else if("attachEvent"in window)e.attachEvent("on"+n,t);else{var o=e["on"+n];e["on"+n]=o?function(e){o(e),t(e)}:t}return e},n=document.querySelectorAll("a[href]");if(n)for(var t in n)n.hasOwnProperty(t)&&e(n[t],"onclick",function(e){new RegExp("^https?://"+location.host,"gi").test(this.href)||(e.preventDefault(),window.postMessage(JSON.stringify({external_url_open:this.href})))})}();';
return (
<WebView
source={{ uri }}
style={styles.webView}
onLoad={() => this.hideSpinner()}
injectedJavaScript={injectedJs}
onMessage={this.onMessage.bind(this)}
scalesPageToFit
javaScriptEnabledAndroid
javaScriptEnabled
onError={(err) => {
this.hideSpinner();
}}
/>
);
}