简体   繁体   中英

VBA SysCmd Compile error (Sub or Function not defined)

I am new to developing code for VBA, I am working on function that runs from an Excel document, the objective is to upload files to sharepoint passing the user credentials, when I compile it I error on SysCmd (Sub or Function not defined), please advice... thanks in advance.

The function is triggered from Excel,

Public Sub CopyToSharePoint()

On Error GoTo err_Copy

    Dim xmlhttp
Dim sharepointUrl
Dim sharepointFileName
Dim tsIn
Dim sBody
Dim LobjXML As Object
Dim UserName As String
Dim pw As String
Dim RetVal
Dim i As Integer
Dim TotFiles As Integer
Dim Start As Date, Finish As Date
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fldr As Object 'Folder
Dim f As Object 'File

Set fldr = fso.GetFolder("c:\vba2sharepoint\")

UserName = "mysharepointusername@domain.com" 
pw = "mysharepointpassword" 
sharepointUrl = "https://mysite.sharepoint.com/sites/xyz-uat/_layouts/15/start.aspx#/a1docsuat/"

Set LobjXML = CreateObject("Microsoft.XMLHTTP")

TotFiles = fldr.Files.Count

For Each f In fldr.Files

 sharepointFileName = sharepointUrl & f.Name

    Set tsIn = f.OpenAsTextStream
    sBody = tsIn.ReadAll
    tsIn.Close

    Set xmlhttp = CreateObject("MSXML2.XMLHTTP.6.0")

    xmlhttp.Open "PUT", sharepointFileName, False, UserName, pw

    xmlhttp.Send sBody

  i = i + 1

  RetVal = SysCmd(acSysCmdSetStatus, "File " & i & " of " & TotFiles & " copied...")

Next f

   RetVal = SysCmd(acSysCmdClearStatus)

  Set LobjXML = Nothing

  Set fso = Nothing

err_Copy:

MsgBox Err & " " & Err.Description

If Err <> 0 Then
  MsgBox Err & " " & Err.Description
  Resume Next
End If

End Sub

SysCmd is an MS Access method ( Application.SysCmd Method ), not an Excel method.

You want to set the status bar text directly as a string passed to an Application.StatusBar object.

 dim msg as string
 msg = "New Statusbar text"
 Application.StatusBar = msg
 Application.StatusBar = "other text"

Either of the last two lines will set the status bar text. To remove custom text, set it to vbNullString .

 Application.StatusBar = vbNullString

See this Excel property reference at Application.StatusBar Property (Excel) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM