sinumerik Posted August 20, 2009 at 05:49 PM Report #283964 Posted August 20, 2009 at 05:49 PM estou a tentar criar 2 ficheiros tipo *.txt em VBA que vai buscar dados a um range, mas quando cria o ficheiro este fica sempre entre aspas o texto que se encontra na célula é por exemplo ;sempreG54II e quando o ficheiro de texto é criado fica ";sempreG54II" coloco aqui o código por mim utilizado e se alguem me poder dar uma luz ...pois sou novo em programação VBA Sub makeFile() Dim ce As Range ' apenas quando estiver 100% Open "\\huron3\0_moldes.wpd\11CENTROS.spf" For Output As #1 Open "\\cam1\moldes\11CENTROS.spf" For Output As #1 For Each ce In Workbooks("11centros.xls").Worksheets("11centros.spf").Range("E1:E33") Write #1, ce.Value Next ce Write #1, "M17" Close #1 Dim cD As Range ' apenas quando estiver 100% Open "\\huron3\0_moldes.wpd\\3CENTROS.spf" For Output As #1 Open "\\cam1\moldes\3CENTROS.spf" For Output As #1 For Each cD In Workbooks("11centros.xls").Worksheets("11centros.spf").Range("E35:E43") Write #1, cD.Value Next cD Write #1, "M17" ' MsgBox "Ficheiros criados com sucesso" Set fs = Application.FileSearch With fs .LookIn = "\\cam1\moldes\" .Filename = "*.spf" If .Execute > 0 Then MsgBox "Foram criados " & .FoundFiles.Count & _ " ficheiro(s)." For i = 1 To .FoundFiles.Count MsgBox .FoundFiles(i) Next i Else MsgBox "Não foram criados quaisquer ficheiros" End If End With Close #1 '' as seguintes linhas eram tentativas para reeditar e gravar mas fica igual ' Workbooks.OpenText Filename:="\\cam1\moldes\3CENTROS.spf", _ DataType:=xlDelimited, tab:=False ' Worksheets("3centros").Columns("A").Replace _ ' What:="G54II", Replacement:="g54II", _ ' SearchOrder:=xlByColumns, MatchCase:=True ' Workbooks("3CENTROS.spf").Close Savechanges:=True End Sub no final o ficheiro fica assim: ";G54II" "$P_UIFR[1,X,TR]=-367.139" "$P_UIFR[1,Y,TR]=-159.705" ";G55II" "$P_UIFR[2,X,TR]=-207.165" "$P_UIFR[2,Y,TR]=-159.698" ";G56II" "$P_UIFR[3,X,TR]=-57.166" "$P_UIFR[3,Y,TR]=-159.674" e deveria ficar: ;G54II $P_UIFR[1,X,TR]=-367.139 $P_UIFR[1,Y,TR]=-159.705 ;G55II $P_UIFR[2,X,TR]=-207.165 $P_UIFR[2,Y,TR]=-159.698 ;G56II $P_UIFR[3,X,TR]=-57.166 $P_UIFR[3,Y,TR]=-159.674
jpaulino Posted August 20, 2009 at 06:27 PM Report #283967 Posted August 20, 2009 at 06:27 PM Olá, Para gravares sem as aspas, tens de gravar como binário Existem vários exemplos e é só procurares 🙂
jpaulino Posted August 20, 2009 at 06:29 PM Report #283968 Posted August 20, 2009 at 06:29 PM Exemplo simples: Dim fileNum As Integer Dim fileSize As Long fileNum = FreeFile Open "c:\teste.txt" For Binary As #fileNum fileSize = LOF(fileNum) Put #fileNum, fileSize + 1, vbNewLine & "Um teste com ficheiros binários" Close #fileNum
sinumerik Posted August 21, 2009 at 08:13 PM Author Report #284090 Posted August 21, 2009 at 08:13 PM foi demasiado fácil a solução...pois bastou substituir write por print muito obrigado pela ajuda binário..apenas iria complicar a leitura de máquina...pois teria que reformatar para a CNC poder ignorar os outros caracteres que iriam aparecer ?
jpaulino Posted August 21, 2009 at 09:39 PM Report #284104 Posted August 21, 2009 at 09:39 PM Boa! 😉 Já à muito que não trabalho com ficheiros de texto dessa forma, mas sei que em modo binário também funciona 🙂
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now