VFP Open docx associated with excel file
RRIOS
0
Reputation points
I have a VFP 9 system. It generates a spreadsheet with data coming from the database. I have a docx file that is associated with this worksheet. In the docx I have some cells that I use the {if{margefield ....}....} to be able to show or not some fields in certain positions.
The problem: when I run the VFP code I want the docx to be opened associated with that worksheet, but that doesn't happen. The docx opens and is not associated with the worksheet. If I open this docx through windows explorer it opens correctly associated with the worksheet.
Copy To Sys(5)+Sys(2003)+'\planilhabasehistorico.xls' Type Xl5
Local oExcel As Excel.Application
try
oExcel = Createobject('Excel.application')
oExcel.Visible = .T. && Deixa o excel visível
oExcel.WindowState= -4137 && Janela maximizada
*oExcel.Workbooks.Open(Sys(5)+Sys(2003)+'\'+ALLTRIM(str(thisform.text1.value,3))+thisform.text2.value+'_'+Thisform.txtsemestre.value+'.xls') && abre teste.xls
oExcel.Workbooks.Open(Sys(5)+Sys(2003)+'\planilhabasehistorico.xls')
oExcel.Cells.Select() && selecionas todas as células
oExcel.Selection.Locked = .F. && "desbloqueio" todas (vem bloqueadas por default)
oExcel.Columns("A:A").Select() && Seleciono a coluna A (código)
oExcel.Selection.Locked = .T. && Bloqueio somente a coluna A
oExcel.Columns("B:B").AutoFit() && Autofit na coluna B (nome)
*oExcel.Quit
*RELEASE oExcel
TRY
m.nameword = Sys(5)+Sys(2003)+'\'+ALLTRIM(tbcontrole.cnomearqhistorico)
*If FILE(m.nameword)
*try
Local oWord As Word.Application
oWord = Createobject("word.application")
*?oword.Documents.Count && 0
*oword.Documents.add()
*?oword.Documents.Count && 1
*?oword.Documents.Item(1).Name
oWord.Documents.open(m.nameword)
oWord.Visible=.T.
*catch
* MESSAGEBOX('O arquivo '+m.nameword+' não existe Verifique !',48,'Aviso do Sistema')
*endtry
CATCH
MESSAGEBOX('Não foi possivel CRIAR o arquivo '+Sys(5)+Sys(2003)+'\'+m.nameword+' Verifique !',48,'Aviso do Sistema')
endtry
CATCH
MESSAGEBOX('Excel / Office não pode ser aberto, Verifique !',48,'Aviso do Sistema')
endtry
Sign in to answer