Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Lloyd Alvarez   on Sep 07 In MS Office Category.

  
Question Answered By: Shayne Anderson   on Sep 07

Sub Importer_fichier_correction()
'
' Importer_fichier_correction Macro
' Macro recorded 07/10/2005 by CacciapuBr01

Dim NbLigne, Nbcara As Integer
Dim rep, nom_fichier, nom_colonne, type_vente, commentaire As
String

' Demande a l'utilisateur le fichier a traiter
rep = Application.GetOpenFilename
Nbcara = Len(rep)
nom_fichier = Mid(rep, 57, Nbcara)

' Demande a l'utilisateur qq infos
nom_colonne = InputBox("Nom de la première colonne: ")
type_vente = InputBox("Volumetric ou Causal?")
commentaire = InputBox("Commentaire : ")

' Ouvre un fichier txt du repertoire Before
Workbooks.OpenText Filename:= _
rep, _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote _
, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,
Comma:= _
False, Space:=False, Other:=True, OtherChar:=";",
FieldInfo:=Array( _
Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5,
2)), TrailingMinusNumbers _
:=True

' Insere une colonne a gauche
Columns("A:A").Select
Selection.Insert Shift:=xlToRight

'nombre de lignes importees
NbLigne = Cells.SpecialCells(xlLastCell).Row

'insere la formule qui permet de formater la ligne
Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=""UC,DS_BE_UC_" & nom_colonne & ",BE,""& RC[1] &"",,""& RC
[2] &"",,"" & RC[3] & "",," & type_vente & ",,,"" & RC[4] & "","" &
RC[5] & "",,,,,,,,,,,'" & commentaire & "'"""

Range([A1], Cells(NbLigne, 1)).Select
Selection.FillDown

'efface la derniere ligne
Range(Cells(NbLigne, 1), Cells(NbLigne, 2)).Select
Selection.ClearContents

Range([A1], Cells(NbLigne, 1)).Select
Selection.Copy
Range("A1").Select
ActiveSheet.PasteSpecial Format:=3, Link:=1,
DisplayAsIcon:=False, IconFileName:=False

Columns("B:F").Select
Selection.ClearContents

ChDir "W:\C19\Sirval\Corrections_BE\After_Format_Input_SIRVAL"
ActiveWorkbook.SaveAs Filename:= _
nom_fichier, FileFormat:=xlText, CreateBackup:=False
End Sub





Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Save Excel file as Text file: smart quotes appear! Or get search suggestion and latest updates.


Tagged: