I am looking for a way to insert a picture from a folder into a specific cell in excel. The folder contains hundreds of pictures. I am not familiar with excel macros or VBA. The way the code should work is I type the picture name into a cell and the result should extract a picture with the same name from that folder and place it into another cell. The picture being inserted should also be resized. If someone could please give me some guidance as to how this could be done. Thanks. I am sorry for my poor English as it is my second language.
Assuming you are typing your image name as "myImage.jpg" into cell A1 of your worksheet. Make sure it is the full name with the extension. Place this into your worksheet code.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim imagePath, fullImagePath, newImageLoc As String
imagePath = "C:\YourFileLocationPath\" 'set this to where your images are located.
If Target.Address = "$A$1" Then 'Assumming the cell you are entering your image is in A1 or change to whatever cell you want entering in.
fullImagePath = imagePath & Target.Value
newImageLoc = Target.Offset(, 2).Address ' this moves the new image location to the cell you enter your image name two columns to the right.
'Adjusts image size, change as needed
With ActiveSheet.Pictures.Insert(fullImagePath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 75
.Height = 100
End With
.Left = ActiveSheet.Range(newImageLoc).Left
.Top = ActiveSheet.Range(newImageLoc).Top
.Placement = 1
.PrintObject = True
End With
End
End If
End Sub
I'm trying to specify the number of lines for NSTextView. My designer is requesting 2 lines of text max. I've tried NSMutableParagraph style to add the ellipses truncation that I want, but with NSMutableParagraph I can only get NSTextView with 1 line and without NSMutableParagraph, I get a scrolling text with as many lines as needed to complete text.
var attributedString = NSMutableAttributedString(string: "This is my text, I can keep going for many characters")
var para = NSMutableParagraphStyle()
para.lineBreakMode = NSLineBreakMode.ByTruncatingTail
let globalAttributes = [
NSParagraphStyleAttributeName: para
]
let range = NSRange(location:0, length: attributedString.length)
attributedString.addAttributes(globalAttributes, range: range)
cellView.myTextView!.textStorage?.setAttributedString(attributedString)
I've tried height constraint on NSTextView. I've tried:
cellView.myTextView!.textContainer?.containerSize = NSMakeSize(300, 32)
I've tried creating IBOutlet for NSScrollView that NSTextView in within and adjusting its height. No luck with getting both 2 lines and truncation. Any help is greatly appreciated. I feel like I'm just missing a method or setup. Thanks!
From 10.11 you can use this
yourTextViewObj.textContainer.maximumNumberOfLines = 2;
You can use an NSTextField configured as a multi-line label. That means setting its cell's wraps property to true and, if desired, its truncatesLastVisibleLine to true.
For NSTextField (aka label) You can just do self.textField.maximumNumberOfLines = 2;
That's it.
Max number of lines is now a property of NSTextField
label.maximumNumberOfLines = 1;
I have a spreadsheet with a picture. I don't know the size of the picture (it may vary).
I want to to get the last row of the picture in a variable (I want to leave a blank row to the bottom of the picture and start filling data in the next row). Could you help me figure out the syntax?
I can't even figure out how to get the picture into a variable..
I was able to do this with the following code:
Dim testPic As Object
For Each testPic In ActiveSheet.Pictures
h = testPic.Height
cellHeight = Cells(ImageTopRow, ImageLeftCol).Height
nRows = h/cellHeight
Next
But:
a. I don't need a foreach, there's only one picture in the collection, I just can't figure out how to get the first one.
b. There should be an easier way, right?
Thanks,
Li
Dim pic As Shape
Set pic = ActiveSheet.Shapes(1)
MsgBox pic.BottomRightCell.Row
will show you the cell's location of the right bottom corner, ie
Hope this will help.
"ActiveSheet.Shapes.Count " - this helps you count the number of pictures in the active sheet
"ActiveSheet.Shapes(1)" - you can just use this if you only have 1 Photo or if you want the bottom right of the 1st photo
Code:
click to view the code Dim pic As Shape
Set pic = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
'Determines the address on the bottom right of the picture
lLast = pic.BottomRightCell.Address
'Selects the Bottom right cell of the Image/picture
Range(lLast).Select
I want to add the lable box value in vb6
Label1 = 200
Label2 = 500
'Adding
Label3 = Label1 + Label2
'Showing output as
Label3 = 200500
I want add the 2 values
Expected Output
Label3 = 700
What was the problem in my code
Need code help
The two answers are correct, but neither of it explain to you why this happens. VB 6 (or 5 or 4 or 3) has a default property for the controls. In the case of the label, the default property is caption. Since caption is a string, and string can be concatenate using & or +, VB pickup the type and then it does the math (in this case, concat).
Label3= val(Label1) + val(Label2)
This works good.. Also you can use Cint or any other convert to number function.
long time haven't worked with VB6 but try
Label3.caption = val(Label1.caption) + val(Label2.caption)
Do something like this:-
textbox3.text = val(textbox1.text) + val(textbox2.text)
How can a MATLAB GUIDE control be used to display the contents of a text file in a GUI? The text file may be very long or very wide so it should have the ability to have vertical and horizontal scroll bars.
A multi-line editbox may be the best choice to display the text. Example:
%# read text file lines as cell array of strings
fid = fopen( fullfile(matlabroot,'license.txt') );
str = textscan(fid, '%s', 'Delimiter','\n'); str = str{1};
fclose(fid);
%# GUI with multi-line editbox
hFig = figure('Menubar','none', 'Toolbar','none');
hPan = uipanel(hFig, 'Title','Display window', ...
'Units','normalized', 'Position',[0.05 0.05 0.9 0.9]);
hEdit = uicontrol(hPan, 'Style','edit', 'FontSize',9, ...
'Min',0, 'Max',2, 'HorizontalAlignment','left', ...
'Units','normalized', 'Position',[0 0 1 1], ...
'String',str);
%# enable horizontal scrolling
jEdit = findjobj(hEdit);
jEditbox = jEdit.getViewport().getComponent(0);
jEditbox.setWrapping(false); %# turn off word-wrapping
jEditbox.setEditable(false); %# non-editable
set(jEdit,'HorizontalScrollBarPolicy',30); %# HORIZONTAL_SCROLLBAR_AS_NEEDED
%# maintain horizontal scrollbar policy which reverts back on component resize
hjEdit = handle(jEdit,'CallbackProperties');
set(hjEdit, 'ComponentResizedCallback',...
'set(gcbo,''HorizontalScrollBarPolicy'',30)')
To enable horizontal scrolling, we must get a handle to the embedded JScrollPane java component. I am using the excellent FINDJOBJ function. Then we set the HorizontalScrollBarPolicy property to javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED (= 30) as explained in this post. I also disabled editing of the text (read only).
Here is my solution for a generic text file called "textfile.txt":
f = figure('menu','none','toolbar','none');
fid = fopen('textfile.txt');
ph = uipanel(f,'Units','normalized','position',[0.4 0.3 0.5 0.5],'title',...
'Display window');
lbh = uicontrol(ph,'style','listbox','Units','normalized','position',...
[0 0 1 1],'FontSize',9);
indic = 1;
while 1
tline = fgetl(fid);
if ~ischar(tline),
break
end
strings{indic}=tline;
indic = indic + 1;
end
fclose(fid);
set(lbh,'string',strings);
set(lbh,'Value',1);
set(lbh,'Selected','on');
Here is my solution. Good Luck
fid = fopen(filename);
str = textscan(fid, '%s', 'Delimiter','\n'); str = str{1};
fclose(fid);
f=figure;
hPan = uipanel(f,'Units','normalized');
uicontrol(hPan, 'Style','listbox', ...
'HorizontalAlignment','left', ...
'Units','normalized', 'Position',[0 0 1 1], ...
'String',str);