在Windows上从vba推送到git [英] push to git from vba on windows
本文介绍了在Windows上从vba推送到git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发word和excel宏,但是为了保持版本控制和跟踪更改,我想使用GitLab
I am developing word and excel macros, however to keep revision control and track changes I would like to use GitLab
所以到目前为止,我运行的代码是在运行publish子例程时将所有vba代码导出到PC上的文件夹中(Z:/Dokumentstyring/GIT):
So what I have done so far is to have a code which export out all vba code to a folder on my PC(Z:/Dokumentstyring/GIT), when I run my publish sub routine:
Private Sub publish()
ThisDocument.save
Call ExportVisualBasicCode
' Here I would like to automatically push the code to GIT
Call CloseAll
End Sub
然后我手动进入git shell并输入:
Then I manually go into git shell and type:
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
有没有办法让我的发布例程为我手动完成此工作?
Is there a way that I can get my publish routine todo this manually work for me?
推荐答案
花了一些时间,但我终于设法解决了这个问题:精简的代码看起来像这样:
It took some time, but I finally manage to solve this issue: The stripped down code looks like this:
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
这篇关于在Windows上从vba推送到git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文