Jump to content

Recommended Posts

Posted

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

Posted

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
Posted

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

?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.