Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.visual-basic > #20009
| Newsgroups | it.comp.lang.visual-basic |
|---|---|
| Date | 2022-12-02 07:03 -0800 |
| References | <d8b29811-7c2e-48ce-9f1a-a51b2b66ad19n@googlegroups.com> |
| Message-ID | <c5eedbb3-ab76-4c4a-8b58-4b1915ed6691n@googlegroups.com> (permalink) |
| Subject | Re: leggere file txt e popolare celle Excel |
| From | Marco75 <marcoporzi75@gmail.com> |
Il giorno venerdì 2 dicembre 2022 alle 15:43:33 UTC+1 Marco75 ha scritto:
> Ciao,
> ho un file txt con 3 informazioni poste su 3 righe.
> vorrei leggere questo file e mettere:
> - contenuto riga 1 in cella C2
> - contenuto riga 2 in cella D2
> - contenuto riga 3 in cella E2
>
> ora ho provato così ma non è corretto...
>
> Dim FilePath As String
> Dim strFirstLine As String
> Dim strSecondLine As String
>
> Dim aFile As String
> aFile = "C:\Interventi macina CQ\Ultima ricetta.txt"
> If Len(Dir$(aFile)) > 0 Then
>
> FilePath = "C:\Interventi macina CQ\Ultima ricetta.txt"
>
> Open FilePath For Input As #1
> Line Input #1, strFirstLine
> MsgBox (strFirstLine)
> Close #1
>
> Open FilePath For Input As #2
> Line Input #2, strFirstLine
> MsgBox (strFirstLine)
> Close #2
>
> End If
>
> in attesa di cortese risposta continuerò a provare
> grazie
> Marco
ho rivisto un po' il codice:
Dim my_file As Integer
Dim text_line As String
Dim file_name As String
Dim i As Integer
Dim aFile As String
aFile = "C:\Interventi macina CQ\Ultima ricetta.txt"
If Len(Dir$(aFile)) > 0 Then
file_name = "C:\Interventi macina CQ\Ultima ricetta.txt"
my_file = FreeFile()
Open file_name For Input As my_file
i = 1
While Not EOF(my_file)
Line Input #my_file, text_line
Cells(i, "H").Value = text_line
i = i + 1
Wend
ActiveSheet.Range("C2").Value = ActiveSheet.Range("H1").Value
ActiveSheet.Range("D2").Value = ActiveSheet.Range("H2").Value
ActiveSheet.Range("E2").Value = ActiveSheet.Range("H3").Value
ActiveSheet.Range("H1:H3").Select
ActiveSheet.Range("H1:H3").ClearContents
ActiveSheet.Range("C2").Select
End If
riesco a leggere il file e mi mette le 3 righe del file nella colonna H (da H1 a H3)
io però le voglio in riga quindi vado a popolarmi le celle poi cancello i dati della colonna H
non è bellissimo ma funziona, resto in attesa di suggerimenti per mettere i 3 dati in C2, D2 ed E2
grazie
Marco
Back to it.comp.lang.visual-basic | Previous | Next — Previous in thread | Next in thread | Find similar
leggere file txt e popolare celle Excel Marco75 <marcoporzi75@gmail.com> - 2022-12-02 06:43 -0800 Re: leggere file txt e popolare celle Excel Marco75 <marcoporzi75@gmail.com> - 2022-12-02 07:03 -0800 Re: leggere file txt e popolare celle Excel "Sauro" <vicchi@crsscala.it> - 2022-12-15 17:00 +0100
csiph-web