我可以打开psql shell并从Excel访问我的nfldb数据库:
Sub atest()
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.Run "cmd /c psql nfldb nfldb"
然后转到shell并从表格' team'中提取信息。在数据库nfldb中的文件' teamNames'用:
nfldb=> \copy (SELECT * FROM team) TO 'C:\temp\teamNames.csv' With CSV
我的问题是我如何从Excel中运行整个代码,以便打开nfldb数据库以及来自' team'表格保存到文件' teamNames'
如何组合这两个代码?
任何帮助将不胜感激!
答案 0 :(得分:0)
如果其他人需要帮助,我经过多次试验和错误后自己解决了这个问题。
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.Run "cmd /c psql -U nfldb -f C:\Python27\writeTeams.sql"
将在psql shell中打开nlfd数据库并运行文件中包含的脚本' writeTeams.sql'