【问题标题】:push to git from vba on windows在 Windows 上从 vba 推送到 git
【发布时间】:2018-05-21 13:33:37
【问题描述】:

我正在开发 word 和 excel 宏,但是为了保持修订控制和跟踪更改,我想使用 GitLab

所以到目前为止我所做的是有一个代码,当我运行我的发布子例程时,它会将所有 vba 代码导出到我的 PC 上的文件夹(Z:/Dokumentstyring/GIT):

Private Sub publish()
    ThisDocument.save

    Call ExportVisualBasicCode
    ' Here I would like to automatically push the code to GIT
    Call CloseAll
End Sub

然后我手动进入 git shell 并输入:

git config --global user.name "xxxxx"
git config --global user.email "xxxx@xxxx.com"

cd Z:/Dokumentstyring/GIT
git init
git remote add origin xxxxxx/xxx/Dokumentstyring.git
git add .
git commit -m "Version Number - Date and a short comment"
git push -u origin master

有没有办法让我的发布例程手动为我工作?

【问题讨论】:

  • 我听不懂你的问题。您知道,一旦设置了存储库,您就不需要每次都运行代码,从您在问题中提到的上述代码中,您只需要运行最后 3 行。如果你解释更多你想要什么,我可能会帮助你

标签: git vba excel ms-word


【解决方案1】:

花了一些时间,但我终于设法解决了这个问题:精简后的代码如下所示:

Private Sub publish()

Dim hFile As Long
Dim FileContents1 As String
Dim versionNumber As String
Dim strFile1 As String
Dim revTekst As String
Dim gitFileCommands As String


revTekst = "Pusher no filene i koden til Github automatisk!!" '& "<BR>" _


versionNumber = Left(wordMakroVersjon, 2) & "." & Right(wordMakroVersjon, Len(wordMakroVersjon) - 2)


Call ExportVisualBasicCode

Call pushToGit(versionNumber, replace(revTekst, "<BR>", vbNewLine))
gitFileCommands = replace(Settings.CMRDISK & "Dokumentstyring\gitCommands.sh", "\", "/")
Shell "C:\Users\kim\AppData\Local\Programs\Git\bin\sh.exe --login -i -c """ & gitFileCommands & """"

End Sub


Public Sub pushToGit(versionNumber As String, releaseNotes As String)

Dim FileContents1 As String
Dim strFile1 As String

strFile1 = Settings.CMRDISK & "Dokumentstyring\gitCommands.sh"

On Error Resume Next
Kill strFile1
On Error GoTo 0

FileContents1 = "#! /bin/bash" & vbNewLine _
    & "cd Z:/Dokumentstyring/GIT" & vbNewLine _
    & "git add ." & vbNewLine _
    & "git commit -m """ & versionNumber & " - " & Format(Now(), "dd.mm.yyyy") & " " & releaseNotes & """" & vbNewLine _
    & "git push -u origin master" & vbNewLine _
    & "read -p ""Press enter to continue"" "


Open strFile1 For Binary As #1
Put #1, , FileContents1
Close #1

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 2011-12-27
    • 2017-03-16
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多