30.03.2017 Views

Excel_VBA_manual

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

.DDEExecute DDE1, ''[EndOfLine 1]''<br />

.DDEExecute DDE1, ''[CenterPara]''<br />

.DDEExecute DDE1, ''[Bold]''<br />

.DDEExecute DDE1, ''[FontSize 32]''<br />

.DDEExecute DDE1, ''[EndOfLine]''<br />

.DDEExecute DDE1, ''[InsertPara]''<br />

.DDETerminate DDE1<br />

End With<br />

End Sub<br />

2.3.3 Funkcije za rad sa datotekama i direktorijima<br />

<strong>VBA</strong> sadrži nekoliko svojstava, metoda i funkcija koje se koriste za izradu i brisanje datoteka i<br />

direktorija, za izmjenu i odreĊivanje putanja te za upisivanje i ĉitanje iz datoteka na tvrdom disku:<br />

AltStartupPath, ChDir, ChDrive, CurDir, DefaultFilePath, Dir, Kill, LibraryPath, MkDir,<br />

PathSeparator, RmDir, SetAttr, StartupPath<br />

Primjer zapisivanja podataka u tekstualnu datoteku pomoću makro programa NapišiuDatoteku<br />

napisanog u <strong>VBA</strong>:<br />

Sub NapišiuDatoteku()<br />

Dim Broj As Integer<br />

Broj = FreeFile()<br />

Open ''C:\Test.txt'' For Output As #Broj<br />

Print # Broj, ''Ovo je primjer.'' &Chr(14)<br />

Write # Broj, 10*10<br />

Close # Broj<br />

End Sub<br />

Makro PročitajizDatoteke služi za uĉitavanje podataka iz tekstualne datoteke i njihov prikaz u<br />

okviru za dijalog:<br />

Sub PročitajizDatoteke()<br />

Dim x As String<br />

Dim St As String<br />

Dim Broj As Integer<br />

Broj = FreeFile()<br />

Open ''C:\Test.txt'' For Input Access Read As # Broj<br />

Do While Not EOF(Broj)<br />

Line Input # Broj, x<br />

St = St & x<br />

Loop<br />

Close # Broj<br />

MsgBox St<br />

EndSub<br />

23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!